mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
Refactor friend request and media services, remove console commands
Refactored the friend request command service and SignalR hub to return and broadcast FriendshipDto objects, improving real-time updates. Enhanced media upload and download logic to support file storage and retrieval, including database integration. Removed all command classes and related infrastructure from the Govor.Console project, streamlining the console client. Updated dependency injection and interfaces to reflect these changes.
This commit is contained in:
@@ -15,7 +15,7 @@ public class FriendRequestCommandService : IFriendRequestCommandService
|
||||
_friendshipsRepository = friendshipsRepository;
|
||||
}
|
||||
|
||||
public async Task SendAsync(Guid fromUserId, Guid toUserId)
|
||||
public async Task<Friendship> SendAsync(Guid fromUserId, Guid toUserId)
|
||||
{
|
||||
if (fromUserId == toUserId)
|
||||
throw new InvalidOperationException("Cannot send a request to self user");
|
||||
@@ -23,16 +23,20 @@ public class FriendRequestCommandService : IFriendRequestCommandService
|
||||
if (_friendshipsRepository.Exist(fromUserId, toUserId))
|
||||
throw new RequestAlreadySentException(fromUserId, toUserId);
|
||||
|
||||
await _friendshipsRepository.AddAsync(new Friendship
|
||||
var friendship = new Friendship
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RequesterId = fromUserId,
|
||||
AddresseeId = toUserId,
|
||||
Status = FriendshipStatus.Pending
|
||||
});
|
||||
};
|
||||
|
||||
await _friendshipsRepository.AddAsync(friendship);
|
||||
|
||||
return friendship;
|
||||
}
|
||||
|
||||
public async Task AcceptAsync(Guid requestId, Guid currentUserId)
|
||||
public async Task<Friendship> AcceptAsync(Guid requestId, Guid currentUserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -46,6 +50,8 @@ public class FriendRequestCommandService : IFriendRequestCommandService
|
||||
|
||||
friendship.Status = FriendshipStatus.Accepted;
|
||||
await _friendshipsRepository.UpdateAsync(friendship);
|
||||
|
||||
return friendship;
|
||||
}
|
||||
catch (NotFoundByKeyException<Guid> ex)
|
||||
{
|
||||
@@ -53,7 +59,7 @@ public class FriendRequestCommandService : IFriendRequestCommandService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RejectAsync(Guid requestId, Guid currentUserId)
|
||||
public async Task<Friendship> RejectAsync(Guid requestId, Guid currentUserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -67,6 +73,7 @@ public class FriendRequestCommandService : IFriendRequestCommandService
|
||||
|
||||
friendship.Status = FriendshipStatus.Rejected;
|
||||
await _friendshipsRepository.UpdateAsync(friendship);
|
||||
return friendship;
|
||||
}
|
||||
catch (NotFoundByKeyException<Guid> ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user