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

View File

@ -1,6 +1,9 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using SessionCompanion.Services.Interfaces; using SessionCompanion.Services.Interfaces;
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
{ {
@ -41,5 +44,29 @@ namespace SessionCompanion.Controllers
Message = "User name not found or incorrect password" 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");
}
} }
} }