diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-03-29 16:58:23 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-03-29 16:58:23 +0300 |
| commit | 9b73e5af74e4aa2f6294b59dee7237a2fa75f26f (patch) | |
| tree | c392b75f6771147e876ee202a16fd291f0c78833 /src/Web/DevHive.Web/Controllers/UserController.cs | |
| parent | 0cf2a3c99141f878168271e53999cdacac95f3c4 (diff) | |
| download | DevHive-fix_friends_authorization.tar DevHive-fix_friends_authorization.tar.gz DevHive-fix_friends_authorization.zip | |
Added initial implmementation of AddFriendfix_friends_authorization
Diffstat (limited to 'src/Web/DevHive.Web/Controllers/UserController.cs')
| -rw-r--r-- | src/Web/DevHive.Web/Controllers/UserController.cs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Web/DevHive.Web/Controllers/UserController.cs b/src/Web/DevHive.Web/Controllers/UserController.cs index 4d01447..2ed8e54 100644 --- a/src/Web/DevHive.Web/Controllers/UserController.cs +++ b/src/Web/DevHive.Web/Controllers/UserController.cs @@ -133,6 +133,26 @@ namespace DevHive.Web.Controllers } #endregion + #region Friends + [HttpPost] + [Route("AddFriend")] + [Authorize(Roles = "User,Admin")] + public async Task<IActionResult> AddFriend(Guid id, [FromBody] UpdateFriendWebModel updateFriendWebModel, [FromHeader] string authorization) + { + if (!this._jwtService.ValidateToken(id, authorization)) + return new UnauthorizedResult(); + + UpdateFriendServiceModel updateFriendServiceModel = this._userMapper.Map<UpdateFriendServiceModel>(updateFriendWebModel); + + bool result = await this._userService.AddFriend(id, updateFriendServiceModel); + + if (!result) + return new BadRequestObjectResult("Could not add User as a friend"); + + return new OkResult(); + } + #endregion + #region Delete /// <summary> /// Delete a User with his Id. A PUSTINQK can only delete his account. An Admin can delete all accounts |
