SES-84 Created User registration method #27

Merged
s426134 merged 3 commits from SES-84 into master 2020-12-13 17:07:56 +01:00
Showing only changes of commit 815bd676d1 - Show all commits

View File

@ -2,6 +2,8 @@
using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.UserViewModels;
using System.Threading.Tasks;
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.ViewModels.ApiResponses;
namespace SessionCompanion.Controllers
{
@ -24,15 +26,27 @@ namespace SessionCompanion.Controllers
return BadRequest();
}
/// <summary>
/// Metoda rejestruje podanego użytkownika
/// </summary>
/// <param name="model"> Model uzytkownika do zarejestrowania </param>
/// <returns> SuccessResponse/ErrorResponse </returns>
[HttpPost("register")]
public async Task<IActionResult> Register(UserViewModel model)
public async Task<Either<SuccessResponse, ErrorResponse>> Register(UserViewModel model)
{
if(!ModelState.IsValid)
return BadRequest();
return new ErrorResponse()
{
StatusCode = 400,
Message = "Given model is incorect"
};
await _service.Create(model);
await _service.SaveAsync();
return Ok();
return new SuccessResponse("User created");
}
}