Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Web / DevHive.Web / Controllers / UserController.cs
diff options
context:
space:
mode:
Commit9b73e5af74e4aa2f6294b59dee7237a2fa75f26f (patch)
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
Filesc392b75f6771147e876ee202a16fd291f0c78833 /src/Web/DevHive.Web/Controllers/UserController.cs
DevHive-fix_friends_authorization.tar
DevHive-fix_friends_authorization.tar.gz
DevHive-fix_friends_authorization.zip
Parent0cf2a3c99141f878168271e53999cdacac95f3c4 (diff)
Added initial implmementation of AddFriend fix_friends_authorization
1 files changed, 20 insertions, 0 deletions
-rw-r--r--src/Web/DevHive.Web/Controllers/UserController.cs20
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