test to make server

This commit is contained in:
Artemy
2026-02-08 22:30:29 +07:00
parent cc2921d257
commit 0a43e35797
56 changed files with 949 additions and 442 deletions
@@ -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)
{