aboutsummaryrefslogtreecommitdiff
path: root/src/Services/DevHive.Services
diff options
context:
space:
mode:
authorDanail Dimitrov <danaildimitrov321@gmail.com>2021-04-07 19:30:04 +0300
committerDanail Dimitrov <danaildimitrov321@gmail.com>2021-04-07 19:30:04 +0300
commit43336a1e977f33ad49ad8b4851ca449936f93ce6 (patch)
treec5170bebb63d1e57bef891905e0c2839766b8a08 /src/Services/DevHive.Services
parentb8d1edfc582bee2ef648757bcad1bbadd075bb08 (diff)
downloadDevHive-43336a1e977f33ad49ad8b4851ca449936f93ce6.tar
DevHive-43336a1e977f33ad49ad8b4851ca449936f93ce6.tar.gz
DevHive-43336a1e977f33ad49ad8b4851ca449936f93ce6.zip
adding functionality to add and remove friends
Diffstat (limited to 'src/Services/DevHive.Services')
-rw-r--r--src/Services/DevHive.Services/Configurations/Mapping/UserMappings.cs3
-rw-r--r--src/Services/DevHive.Services/Interfaces/IFriendsService.cs4
-rw-r--r--src/Services/DevHive.Services/Services/FriendsService.cs33
3 files changed, 30 insertions, 10 deletions
diff --git a/src/Services/DevHive.Services/Configurations/Mapping/UserMappings.cs b/src/Services/DevHive.Services/Configurations/Mapping/UserMappings.cs
index 99b41a8..5a39f73 100644
--- a/src/Services/DevHive.Services/Configurations/Mapping/UserMappings.cs
+++ b/src/Services/DevHive.Services/Configurations/Mapping/UserMappings.cs
@@ -23,6 +23,9 @@ namespace DevHive.Services.Configurations.Mapping
CreateMap<User, UpdateUserServiceModel>()
.ForMember(dest => dest.ProfilePictureURL, src => src.MapFrom(p => p.ProfilePicture.PictureURL));
CreateMap<User, FriendServiceModel>();
+
+ CreateMap<UserServiceModel, UpdateUserServiceModel>();
+ CreateMap<UserServiceModel, UpdateFriendServiceModel>();
}
}
}
diff --git a/src/Services/DevHive.Services/Interfaces/IFriendsService.cs b/src/Services/DevHive.Services/Interfaces/IFriendsService.cs
index 6ab7b90..e337793 100644
--- a/src/Services/DevHive.Services/Interfaces/IFriendsService.cs
+++ b/src/Services/DevHive.Services/Interfaces/IFriendsService.cs
@@ -5,7 +5,7 @@ namespace DevHive.Services.Interfaces
{
public interface IFriendsService
{
- Task<object> AddFriend(Guid userId, Guid friendId);
- Task<object> RemoveFriend(Guid userId, Guid friendId);
+ Task<bool> AddFriend(Guid userId, Guid friendId);
+ Task<bool> RemoveFriend(Guid userId, Guid friendId);
}
}
diff --git a/src/Services/DevHive.Services/Services/FriendsService.cs b/src/Services/DevHive.Services/Services/FriendsService.cs
index 7577572..6d4ee73 100644
--- a/src/Services/DevHive.Services/Services/FriendsService.cs
+++ b/src/Services/DevHive.Services/Services/FriendsService.cs
@@ -1,8 +1,10 @@
using System;
+using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using DevHive.Common.Jwt.Interfaces;
using DevHive.Services.Interfaces;
+using DevHive.Services.Models.User;
namespace DevHive.Services.Services
{
@@ -10,25 +12,40 @@ namespace DevHive.Services.Services
{
private readonly IUserService _userService;
private readonly IMapper _userMapper;
- private readonly IJwtService _jwtService;
public FriendsService(IUserService userService,
- IMapper mapper,
- IJwtService jwtService)
+ IMapper mapper)
{
this._userService = userService;
this._userMapper = mapper;
- this._jwtService = jwtService;
}
- public async Task<object> AddFriend(Guid userId, Guid friendId)
+ public async Task<bool> AddFriend(Guid userId, Guid friendId)
{
- return new { Message = "FUCK YOU" };
+ UserServiceModel user = await this._userService.GetUserById(userId);
+ UserServiceModel friendUser = await this._userService.GetUserById(friendId);
+
+ UpdateUserServiceModel updateUser = this._userMapper.Map<UpdateUserServiceModel>(user);
+ UpdateFriendServiceModel updatefriendUser = this._userMapper.Map<UpdateFriendServiceModel>(friendUser);
+
+ updateUser.Friends.Add(updatefriendUser);
+
+ return (await this._userService.UpdateUser(updateUser))
+ .Friends.Any(x => x.Id == friendId);
}
- public async Task<object> RemoveFriend(Guid userId, Guid friendId)
+ public async Task<bool> RemoveFriend(Guid userId, Guid friendId)
{
- return new { Message = "FUCK YOU" };
+ UserServiceModel user = await this._userService.GetUserById(userId);
+ UserServiceModel friendUser = await this._userService.GetUserById(friendId);
+
+ UpdateUserServiceModel updateUser = this._userMapper.Map<UpdateUserServiceModel>(user);
+ UpdateFriendServiceModel updatefriendUser = this._userMapper.Map<UpdateFriendServiceModel>(friendUser);
+
+ updateUser.Friends.Remove(updatefriendUser);
+
+ return !(await this._userService.UpdateUser(updateUser))
+ .Friends.Any(x => x.Id == friendId);
}
}
}