aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2020-12-16 17:48:55 +0200
committertranstrike <transtrike@gmail.com>2020-12-16 17:48:55 +0200
commit534f3012d19b8a8a114153c11e7f8109577ac6e9 (patch)
tree2cb5d8cf7ba82ac99314c641e5ce6b9d4de753c1 /src/DevHive.Web
parent47c2a91612b54329ba0353b1296846bafc0e9775 (diff)
downloadDevHive-534f3012d19b8a8a114153c11e7f8109577ac6e9.tar
DevHive-534f3012d19b8a8a114153c11e7f8109577ac6e9.tar.gz
DevHive-534f3012d19b8a8a114153c11e7f8109577ac6e9.zip
Fixed User Service and User Controller return types
Diffstat (limited to 'src/DevHive.Web')
-rw-r--r--src/DevHive.Web/Configurations/Mapping/UserMappings.cs2
-rw-r--r--src/DevHive.Web/Controllers/UserController.cs26
-rw-r--r--src/DevHive.Web/Models/Identity/User/TokenWebModel.cs12
3 files changed, 33 insertions, 7 deletions
diff --git a/src/DevHive.Web/Configurations/Mapping/UserMappings.cs b/src/DevHive.Web/Configurations/Mapping/UserMappings.cs
index 06083de..1fdfc6a 100644
--- a/src/DevHive.Web/Configurations/Mapping/UserMappings.cs
+++ b/src/DevHive.Web/Configurations/Mapping/UserMappings.cs
@@ -15,6 +15,8 @@ namespace DevHive.Web.Configurations.Mapping
CreateMap<UpdateUserWebModel, UpdateUserServiceModel>();
CreateMap<UserServiceModel, UserWebModel>();
+
+ CreateMap<TokenServiceModel, TokenWebModel>();
}
}
}
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<LoginServiceModel>(loginModel);
- return await this._userService.LoginUser(loginServiceModel);
+ TokenServiceModel tokenServiceModel = await this._userService.LoginUser(loginServiceModel);
+ TokenWebModel tokenWebModel = this._userMapper.Map<TokenWebModel>(tokenServiceModel);
+
+ return new OkObjectResult(tokenWebModel);
}
[HttpPost]
@@ -40,27 +43,35 @@ namespace DevHive.Web.Controllers
{
RegisterServiceModel registerServiceModel = this._userMapper.Map<RegisterServiceModel>(registerModel);
- return await this._userService.RegisterUser(registerServiceModel);
+ UserServiceModel userServiceModel = await this._userService.RegisterUser(registerServiceModel);
+ UserWebModel userWebModel = this._userMapper.Map<UserWebModel>(userServiceModel);
+
+ return new CreatedResult("Register", userWebModel);
}
//Read
[HttpGet]
public async Task<IActionResult> GetById(Guid id)
{
- UserServiceModel serviceModel = await this._userService.GetUserById(id);
+ UserServiceModel userServiceModel = await this._userService.GetUserById(id);
+ UserWebModel userWebModel = this._userMapper.Map<UserWebModel>(userServiceModel);
- return new OkObjectResult(this._userMapper.Map<UserWebModel>(serviceModel));
+ return new OkObjectResult(userWebModel);
}
//Update
[HttpPut]
- [Authorize]
+ [Authorize(Roles = Role.DefaultRole)]
public async Task<IActionResult> Update(Guid id, [FromBody] UpdateUserWebModel updateModel)
{
UpdateUserServiceModel updateUserServiceModel = this._userMapper.Map<UpdateUserServiceModel>(updateModel);
updateUserServiceModel.Id = id;
- return await this._userService.UpdateUser(updateUserServiceModel);
+ UserServiceModel userServiceModel = await this._userService.UpdateUser(updateUserServiceModel);
+ UserWebModel userWebModel = this._userMapper.Map<UserWebModel>(userServiceModel);
+
+ return new AcceptedResult("UpdateUser", userWebModel);
+
}
//Delete
@@ -68,7 +79,8 @@ namespace DevHive.Web.Controllers
[Authorize(Roles = Role.DefaultRole)]
public async Task<IActionResult> Delete(Guid id)
{
- return await this._userService.DeleteUser(id);
+ await this._userService.DeleteUser(id);
+ return new OkResult();
}
}
}
diff --git a/src/DevHive.Web/Models/Identity/User/TokenWebModel.cs b/src/DevHive.Web/Models/Identity/User/TokenWebModel.cs
new file mode 100644
index 0000000..154b64b
--- /dev/null
+++ b/src/DevHive.Web/Models/Identity/User/TokenWebModel.cs
@@ -0,0 +1,12 @@
+namespace DevHive.Web.Models.Identity.User
+{
+ public class TokenWebModel
+ {
+ public TokenWebModel(string token)
+ {
+ this.Token = token;
+ }
+
+ public string Token { get; set; }
+ }
+} \ No newline at end of file