From 534f3012d19b8a8a114153c11e7f8109577ac6e9 Mon Sep 17 00:00:00 2001 From: transtrike Date: Wed, 16 Dec 2020 17:48:55 +0200 Subject: Fixed User Service and User Controller return types --- src/DevHive.Web/Controllers/UserController.cs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/DevHive.Web/Controllers') diff --git a/src/DevHive.Web/Controllers/UserController.cs b/src/DevHive.Web/Controllers/UserController.cs index 74eccd4..44828e0 100644 --- a/src/DevHive.Web/Controllers/UserController.cs +++ b/src/DevHive.Web/Controllers/UserController.cs @@ -31,7 +31,10 @@ namespace DevHive.Web.Controllers { LoginServiceModel loginServiceModel = this._userMapper.Map(loginModel); - return await this._userService.LoginUser(loginServiceModel); + TokenServiceModel tokenServiceModel = await this._userService.LoginUser(loginServiceModel); + TokenWebModel tokenWebModel = this._userMapper.Map(tokenServiceModel); + + return new OkObjectResult(tokenWebModel); } [HttpPost] @@ -40,27 +43,35 @@ namespace DevHive.Web.Controllers { RegisterServiceModel registerServiceModel = this._userMapper.Map(registerModel); - return await this._userService.RegisterUser(registerServiceModel); + UserServiceModel userServiceModel = await this._userService.RegisterUser(registerServiceModel); + UserWebModel userWebModel = this._userMapper.Map(userServiceModel); + + return new CreatedResult("Register", userWebModel); } //Read [HttpGet] public async Task GetById(Guid id) { - UserServiceModel serviceModel = await this._userService.GetUserById(id); + UserServiceModel userServiceModel = await this._userService.GetUserById(id); + UserWebModel userWebModel = this._userMapper.Map(userServiceModel); - return new OkObjectResult(this._userMapper.Map(serviceModel)); + return new OkObjectResult(userWebModel); } //Update [HttpPut] - [Authorize] + [Authorize(Roles = Role.DefaultRole)] public async Task Update(Guid id, [FromBody] UpdateUserWebModel updateModel) { UpdateUserServiceModel updateUserServiceModel = this._userMapper.Map(updateModel); updateUserServiceModel.Id = id; - return await this._userService.UpdateUser(updateUserServiceModel); + UserServiceModel userServiceModel = await this._userService.UpdateUser(updateUserServiceModel); + UserWebModel userWebModel = this._userMapper.Map(userServiceModel); + + return new AcceptedResult("UpdateUser", userWebModel); + } //Delete @@ -68,7 +79,8 @@ namespace DevHive.Web.Controllers [Authorize(Roles = Role.DefaultRole)] public async Task Delete(Guid id) { - return await this._userService.DeleteUser(id); + await this._userService.DeleteUser(id); + return new OkResult(); } } } -- cgit v1.2.3