mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
test to make server
This commit is contained in:
@@ -19,20 +19,35 @@ public class FriendRequestCommandService : IFriendRequestCommandService
|
||||
{
|
||||
if (fromUserId == toUserId)
|
||||
throw new InvalidOperationException("Cannot send a request to self user");
|
||||
|
||||
var friendship = await _friendshipsRepository.GetFriendshipAsync(fromUserId, toUserId);
|
||||
|
||||
if (_friendshipsRepository.Exist(fromUserId, toUserId))
|
||||
throw new RequestAlreadySentException(fromUserId, toUserId);
|
||||
|
||||
var friendship = new Friendship
|
||||
if (friendship is null)
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RequesterId = fromUserId,
|
||||
AddresseeId = toUserId,
|
||||
Status = FriendshipStatus.Pending
|
||||
};
|
||||
|
||||
await _friendshipsRepository.AddAsync(friendship);
|
||||
friendship = new Friendship
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RequesterId = fromUserId,
|
||||
AddresseeId = toUserId,
|
||||
Status = FriendshipStatus.Pending
|
||||
};
|
||||
await _friendshipsRepository.AddAsync(friendship);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (friendship.Status == FriendshipStatus.Pending || friendship.Status == FriendshipStatus.Accepted
|
||||
|| friendship.Status == FriendshipStatus.Blocked)
|
||||
{
|
||||
throw new RequestAlreadySentException(fromUserId, toUserId);
|
||||
}
|
||||
|
||||
friendship.RequesterId = fromUserId;
|
||||
friendship.AddresseeId = toUserId;
|
||||
friendship.Status = FriendshipStatus.Pending;
|
||||
|
||||
await _friendshipsRepository.UpdateAsync(friendship);
|
||||
}
|
||||
|
||||
return friendship;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ public class FriendshipService : IFriendshipService
|
||||
_friendshipsRepository = friendshipsRepository;
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<User>> SearchUsersAsync(string query, Guid currentId)
|
||||
{
|
||||
List<User> all = new List<User>();
|
||||
@@ -42,6 +43,23 @@ public class FriendshipService : IFriendshipService
|
||||
throw new UnauthorizedAccessException($"When we try find friends by pattern {query} something wrong", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<User>> GetPotentialFriendsAsync(Guid userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var friendships = await _friendshipsRepository.FindByUserIdAsync(userId);
|
||||
|
||||
return friendships
|
||||
.Where(f => f.Status == FriendshipStatus.Pending)
|
||||
.Select(f => f.RequesterId == userId ? f.Addressee : f.Requester)
|
||||
.ToList();
|
||||
}
|
||||
catch (NotFoundByKeyException<Guid> ex)
|
||||
{
|
||||
throw new InvalidOperationException("Nothing was found for the specified id.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<User>> GetFriendsAsync(Guid userId)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user