mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
Refactor friend request services and add SignalR error handling
Split IFriendRequestService into command and query interfaces, refactor related services and tests, and update dependency injection. Add HubResult response model and a SignalR HubExceptionFilter for consistent error handling. Move and update FriendsHub to use new command service and result pattern. Update username validation to allow digits after Cyrillic letters. Add new controllers and configuration for SignalR. Remove obsolete IFriendRequestService and related code.
This commit is contained in:
+6
-34
@@ -6,16 +6,16 @@ using Govor.Data.Repositories.Exceptions;
|
||||
|
||||
namespace Govor.Application.Services.Friends;
|
||||
|
||||
public class FriendRequestService : IFriendRequestService
|
||||
public class FriendRequestCommandService : IFriendRequestCommandService
|
||||
{
|
||||
private readonly IFriendshipsRepository _friendshipsRepository;
|
||||
|
||||
public FriendRequestService(IFriendshipsRepository friendshipsRepository)
|
||||
public FriendRequestCommandService(IFriendshipsRepository friendshipsRepository)
|
||||
{
|
||||
_friendshipsRepository = friendshipsRepository;
|
||||
}
|
||||
|
||||
public async Task SendFriendRequestAsync(Guid fromUserId, Guid toUserId)
|
||||
|
||||
public async Task SendAsync(Guid fromUserId, Guid toUserId)
|
||||
{
|
||||
if (fromUserId == toUserId)
|
||||
throw new InvalidOperationException("Cannot send a request to self user");
|
||||
@@ -32,7 +32,7 @@ public class FriendRequestService : IFriendRequestService
|
||||
});
|
||||
}
|
||||
|
||||
public async Task AcceptFriendRequestAsync(Guid requestId, Guid currentUserId)
|
||||
public async Task AcceptAsync(Guid requestId, Guid currentUserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -53,7 +53,7 @@ public class FriendRequestService : IFriendRequestService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RejectFriendRequestAsync(Guid requestId, Guid currentUserId)
|
||||
public async Task RejectAsync(Guid requestId, Guid currentUserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -73,32 +73,4 @@ public class FriendRequestService : IFriendRequestService
|
||||
throw new InvalidOperationException("Friendship not found! You cant reject request!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<Friendship>> GetIncomingRequestsAsync(Guid userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var friendships = await _friendshipsRepository.FindByUserIdAsync(userId);
|
||||
return friendships.Where(f => f.AddresseeId == userId && f.Status == FriendshipStatus.Pending).ToList()
|
||||
?? new List<Friendship>();
|
||||
}
|
||||
catch (NotFoundByKeyException<Guid> ex)
|
||||
{
|
||||
throw new InvalidOperationException("User not exist", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<Friendship>> GetResponsesAsync(Guid userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var friendships = await _friendshipsRepository.FindByUserIdAsync(userId);
|
||||
return friendships.Where(f => f.RequesterId == userId && f.Status != FriendshipStatus.Accepted).ToList()
|
||||
?? new List<Friendship>();
|
||||
}
|
||||
catch (NotFoundByKeyException<Guid> ex)
|
||||
{
|
||||
throw new InvalidOperationException("User not exist", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Govor.Application.Interfaces.Friends;
|
||||
using Govor.Core.Models;
|
||||
using Govor.Core.Repositories.Friendships;
|
||||
using Govor.Data.Repositories.Exceptions;
|
||||
|
||||
namespace Govor.Application.Services.Friends;
|
||||
|
||||
public class FriendRequestQueryService : IFriendRequestQueryService
|
||||
{
|
||||
private readonly IFriendshipsRepository _friendshipsRepository;
|
||||
|
||||
public FriendRequestQueryService(IFriendshipsRepository friendshipsRepository)
|
||||
{
|
||||
_friendshipsRepository = friendshipsRepository;
|
||||
}
|
||||
|
||||
public async Task<List<Friendship>> GetIncomingAsync(Guid userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var friendships = await _friendshipsRepository.FindByUserIdAsync(userId);
|
||||
return friendships.Where(f => f.AddresseeId == userId && f.Status == FriendshipStatus.Pending).ToList()
|
||||
?? new List<Friendship>();
|
||||
}
|
||||
catch (NotFoundByKeyException<Guid> ex)
|
||||
{
|
||||
throw new InvalidOperationException("User not exist", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<Friendship>> GetResponsesAsync(Guid userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var friendships = await _friendshipsRepository.FindByUserIdAsync(userId);
|
||||
return friendships.Where(f => f.RequesterId == userId && f.Status != FriendshipStatus.Accepted).ToList()
|
||||
?? new List<Friendship>();
|
||||
}
|
||||
catch (NotFoundByKeyException<Guid> ex)
|
||||
{
|
||||
throw new InvalidOperationException("User not exist", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user