From 54d081a513117c732ab4d62312b440d37dfe0d67 Mon Sep 17 00:00:00 2001 From: transtrike Date: Tue, 15 Dec 2020 19:38:50 +0200 Subject: User Controller, Service & Data implemented --- src/DevHive.Web/Controllers/UserController.cs | 31 +++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/DevHive.Web/Controllers/UserController.cs') diff --git a/src/DevHive.Web/Controllers/UserController.cs b/src/DevHive.Web/Controllers/UserController.cs index 14ecb73..480fbe4 100644 --- a/src/DevHive.Web/Controllers/UserController.cs +++ b/src/DevHive.Web/Controllers/UserController.cs @@ -2,6 +2,7 @@ using System; using System.Threading.Tasks; using AutoMapper; using DevHive.Data.Repositories; +using DevHive.Services.Models.Identity.User; using DevHive.Services.Options; using DevHive.Services.Services; using DevHive.Web.Models.Identity.User; @@ -15,44 +16,47 @@ namespace DevHive.Web.Controllers public class UserController: ControllerBase { private readonly UserService _service; + private readonly IMapper _userMapper; public UserController(DevHiveContext context, IMapper mapper, JWTOptions jwtOptions) { this._service = new UserService(context, mapper, jwtOptions); + this._userMapper = mapper; } [HttpPost] [Route("Login")] - public async Task Login([FromBody] LoginWebModel loginWebModel) + public async Task Login([FromBody] LoginWebModel loginModel) { - var loginDTO = - return await this._service.LoginUser(loginDTO); - //throw new NotImplementedException(); + LoginServiceModel loginServiceModel = this._userMapper.Map(loginModel); + + return await this._service.LoginUser(loginServiceModel); } [HttpPost] [Route("Register")] - public async Task Register([FromBody] RegisterWebModel registerWebModel) + public async Task Register([FromBody] RegisterWebModel registerModel) { - //return await this._service.RegisterUser(registerDto); - throw new NotImplementedException(); + RegisterServiceModel registerServiceModel = this._userMapper.Map(registerModel); + + return await this._service.RegisterUser(registerServiceModel); } //Read [HttpGet] public async Task GetById(Guid id) { - //return await this._service.GetUserById(id); - throw new NotImplementedException(); + return await this._service.GetUserById(id); } //Update [HttpPut] [Authorize] - public async Task Update(Guid id, [FromBody] UpdateUserWebModel updateUserWebModel) + public async Task Update(Guid id, [FromBody] UpdateUserWebModel updateModel) { - //return await this._service.UpdateUser(id, userDTO); - throw new NotImplementedException(); + UpdateUserServiceModel updateUserServiceModel = this._userMapper.Map(updateModel); + + return await this._service.UpdateUser(id, updateUserServiceModel); } //Delete @@ -60,8 +64,7 @@ namespace DevHive.Web.Controllers [Authorize] public async Task Delete(Guid id) { - //return await this._service.DeleteUser(id); - throw new NotImplementedException(); + return await this._service.DeleteUser(id); } } } -- cgit v1.2.3