aboutsummaryrefslogtreecommitdiff
path: root/src/Web/DevHive.Web
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-03-29 16:58:23 +0300
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-03-29 16:58:23 +0300
commit9b73e5af74e4aa2f6294b59dee7237a2fa75f26f (patch)
treec392b75f6771147e876ee202a16fd291f0c78833 /src/Web/DevHive.Web
parent0cf2a3c99141f878168271e53999cdacac95f3c4 (diff)
downloadDevHive-9b73e5af74e4aa2f6294b59dee7237a2fa75f26f.tar
DevHive-9b73e5af74e4aa2f6294b59dee7237a2fa75f26f.tar.gz
DevHive-9b73e5af74e4aa2f6294b59dee7237a2fa75f26f.zip
Added initial implmementation of AddFriendfix_friends_authorization
Diffstat (limited to 'src/Web/DevHive.Web')
-rw-r--r--src/Web/DevHive.Web/Configurations/Mapping/UserMappings.cs3
-rw-r--r--src/Web/DevHive.Web/Controllers/UserController.cs20
2 files changed, 23 insertions, 0 deletions
diff --git a/src/Web/DevHive.Web/Configurations/Mapping/UserMappings.cs b/src/Web/DevHive.Web/Configurations/Mapping/UserMappings.cs
index 14aaa3a..1c193e8 100644
--- a/src/Web/DevHive.Web/Configurations/Mapping/UserMappings.cs
+++ b/src/Web/DevHive.Web/Configurations/Mapping/UserMappings.cs
@@ -28,6 +28,9 @@ namespace DevHive.Web.Configurations.Mapping
CreateMap<UpdateUserServiceModel, UpdateUserWebModel>();
CreateMap<FriendServiceModel, UsernameWebModel>();
+
+ // Friends
+ CreateMap<UpdateFriendWebModel, UpdateFriendServiceModel>();
}
}
}
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