From 9b73e5af74e4aa2f6294b59dee7237a2fa75f26f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 29 Mar 2021 16:58:23 +0300 Subject: Added initial implmementation of AddFriend --- src/Services/DevHive.Services/Interfaces/IUserService.cs | 2 ++ src/Services/DevHive.Services/Services/UserService.cs | 15 +++++++++++++++ 2 files changed, 17 insertions(+) (limited to 'src/Services') 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 /// The new picture's URL Task UpdateProfilePicture(UpdateProfilePictureServiceModel updateProfilePictureServiceModel); + Task AddFriend(Guid id, UpdateFriendServiceModel updateFriendServiceModel); + /// /// 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 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 }); + + return await this._userRepository.EditAsync(id, user); + } + #endregion + #region Delete public async Task DeleteUser(Guid id) { -- cgit v1.2.3