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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user