Merge pull request 'SES-84 Created User registration method' (#27) from SES-84 into master

Reviewed-on: #27
This commit is contained in:
Łukasz Góreczny 2020-12-13 17:07:55 +01:00
commit 79f6bede98

View File

@ -1,6 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.UserViewModels;
using System.Threading.Tasks;
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.ViewModels.ApiResponses;
namespace SessionCompanion.Controllers
{
@ -41,5 +44,29 @@ namespace SessionCompanion.Controllers
Message = "User name not found or incorrect password"
};
}
/// <summary>
/// Metoda rejestruje podanego użytkownika
/// </summary>
/// <param name="model"> Model uzytkownika do zarejestrowania </param>
/// <returns> SuccessResponse/ErrorResponse </returns>
[HttpPost("register")]
public async Task<Either<SuccessResponse, ErrorResponse>> Register(UserViewModel model)
{
if(!ModelState.IsValid)
return new ErrorResponse()
{
StatusCode = 400,
Message = "Given model is incorect"
};
await _service.Create(model);
await _service.SaveAsync();
return new SuccessResponse("User created");
}
}
}