SES-84 Created User registration method #27
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user