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