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/Services/DevHive.Services | |
| parent | 0cf2a3c99141f878168271e53999cdacac95f3c4 (diff) | |
| download | DevHive-9b73e5af74e4aa2f6294b59dee7237a2fa75f26f.tar DevHive-9b73e5af74e4aa2f6294b59dee7237a2fa75f26f.tar.gz DevHive-9b73e5af74e4aa2f6294b59dee7237a2fa75f26f.zip | |
Added initial implmementation of AddFriendfix_friends_authorization
Diffstat (limited to 'src/Services/DevHive.Services')
| -rw-r--r-- | src/Services/DevHive.Services/Interfaces/IUserService.cs | 2 | ||||
| -rw-r--r-- | src/Services/DevHive.Services/Services/UserService.cs | 15 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/Services/DevHive.Services/Interfaces/IUserService.cs b/src/Services/DevHive.Services/Interfaces/IUserService.cs index a55f9dd..47948f4 100644 --- a/src/Services/DevHive.Services/Interfaces/IUserService.cs +++ b/src/Services/DevHive.Services/Interfaces/IUserService.cs @@ -52,6 +52,8 @@ namespace DevHive.Services.Interfaces /// <returns>The new picture's URL</returns> Task<ProfilePictureServiceModel> UpdateProfilePicture(UpdateProfilePictureServiceModel updateProfilePictureServiceModel); + Task<bool> AddFriend(Guid id, UpdateFriendServiceModel updateFriendServiceModel); + /// <summary> /// Deletes a user from the database and removes his data entirely /// Requires authenticated user diff --git a/src/Services/DevHive.Services/Services/UserService.cs b/src/Services/DevHive.Services/Services/UserService.cs index 4f74b06..ed8940e 100644 --- a/src/Services/DevHive.Services/Services/UserService.cs +++ b/src/Services/DevHive.Services/Services/UserService.cs @@ -143,6 +143,21 @@ namespace DevHive.Services.Services } #endregion + #region Friends + public async Task<bool> AddFriend(Guid id, UpdateFriendServiceModel updateFriendServiceModel) + { + User user = await this._userRepository.GetByIdAsync(id) ?? + throw new ArgumentException("Cannot add friend to user, because user does not exist!"); + + if (!await this._userRepository.DoesUserExistAsync(updateFriendServiceModel.Id)) + throw new ArgumentException("Cannot add friend to user, because friend does not exist!"); + + await this.CreateRelationToFriends(user, new List<UpdateFriendServiceModel> { updateFriendServiceModel }); + + return await this._userRepository.EditAsync(id, user); + } + #endregion + #region Delete public async Task<bool> DeleteUser(Guid id) { |
