From 6f8cf6dcb45de9ae27d1c072977a86ff0b29421f Mon Sep 17 00:00:00 2001 From: Kosma Date: Sun, 13 Dec 2020 12:45:50 +0100 Subject: [PATCH 1/2] UserController.cs change --- .../SessionCompanion/Controllers/UserController.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/SessionCompanion/SessionCompanion/Controllers/UserController.cs b/SessionCompanion/SessionCompanion/Controllers/UserController.cs index 00dff03..da697bf 100644 --- a/SessionCompanion/SessionCompanion/Controllers/UserController.cs +++ b/SessionCompanion/SessionCompanion/Controllers/UserController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using SessionCompanion.Services.Interfaces; +using SessionCompanion.ViewModels.UserViewModels; using System.Threading.Tasks; namespace SessionCompanion.Controllers @@ -22,5 +23,17 @@ namespace SessionCompanion.Controllers if (User.Password == password) { return Json(User.Id); } return BadRequest(); } + + [HttpPost("register")] + + public async Task Register(UserViewModel model) + { + if(!ModelState.IsValid) + return BadRequest(); + await _service.Create(model); + await _service.SaveAsync(); + return Ok(); + } + } } \ No newline at end of file -- 2.20.1 From 815bd676d1077383c82a110e5d235014c7bdf34f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20G=C3=B3reczny?= Date: Sun, 13 Dec 2020 13:22:09 +0100 Subject: [PATCH 2/2] SES-84 Change type to Either --- .../Controllers/UserController.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/SessionCompanion/SessionCompanion/Controllers/UserController.cs b/SessionCompanion/SessionCompanion/Controllers/UserController.cs index da697bf..c577be9 100644 --- a/SessionCompanion/SessionCompanion/Controllers/UserController.cs +++ b/SessionCompanion/SessionCompanion/Controllers/UserController.cs @@ -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(); } + + /// + /// Metoda rejestruje podanego użytkownika + /// + /// Model uzytkownika do zarejestrowania + /// SuccessResponse/ErrorResponse [HttpPost("register")] - public async Task Register(UserViewModel model) + public async Task> 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"); } } -- 2.20.1