aboutsummaryrefslogtreecommitdiff
path: root/src/Services/DevHive.Services
diff options
context:
space:
mode:
Diffstat (limited to 'src/Services/DevHive.Services')
-rw-r--r--src/Services/DevHive.Services/Interfaces/IUserService.cs2
-rw-r--r--src/Services/DevHive.Services/Services/UserService.cs15
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)
{