-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#125) frined serice external event udpate
- Loading branch information
1 parent
daba825
commit 745b2fc
Showing
4 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...niSpace.Services.Friends.Application/Events/External/Handlers/FriendRequestSentHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using Convey.CQRS.Events; | ||
using MiniSpace.Services.Friends.Application.Events.External; | ||
using MiniSpace.Services.Friends.Application.Exceptions; | ||
using MiniSpace.Services.Friends.Application.Services; | ||
using MiniSpace.Services.Friends.Core.Repositories; | ||
using MiniSpace.Services.Friends.Core.Entities; | ||
|
||
namespace MiniSpace.Services.Friends.Application.Commands.Handlers | ||
{ | ||
public class FriendRequestSentHandler : IEventHandler<FriendRequestSent> | ||
{ | ||
private readonly IFriendRepository _friendRepository; | ||
private readonly IEventMapper _eventMapper; | ||
private readonly IMessageBroker _messageBroker; | ||
private readonly IAppContext _appContext; | ||
|
||
public FriendRequestSentHandler(IFriendRepository friendRepository, IEventMapper eventMapper, IMessageBroker messageBroker, IAppContext appContext) | ||
{ | ||
_friendRepository = friendRepository; | ||
_eventMapper = eventMapper; | ||
_messageBroker = messageBroker; | ||
_appContext = appContext; | ||
} | ||
|
||
// public async Task HandleAsync(FriendRequestSent @event, CancellationToken cancellationToken) | ||
// { | ||
// var now = DateTime.UtcNow; | ||
// var request = new FriendRequest( | ||
// inviterId: @event.InviterId, | ||
// inviteeId: @event.InviteeId, | ||
// requestedAt: now, | ||
// state: FriendState.Requested | ||
// ); | ||
// await _friendRepository.AddRequestAsync(request); | ||
|
||
// var events = _eventMapper.MapAll(request.Events); | ||
// await _messageBroker.PublishAsync(events.ToArray()); | ||
// // Console.WriteLine($"FriendInvited event published: InviterId={@event.InviterId}, InviteeId={@event.InviteeId}"); | ||
// } | ||
|
||
public async Task HandleAsync(FriendRequestSent @event, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
var request = new FriendRequest( | ||
inviterId: @event.InviterId, | ||
inviteeId: @event.InviteeId, | ||
requestedAt: DateTime.UtcNow, | ||
state: FriendState.Requested | ||
); | ||
|
||
// await _friendRepository.AddRequestAsync(request); | ||
var events = _eventMapper.MapAll(request.Events); | ||
await _messageBroker.PublishAsync(events.ToArray()); | ||
} | ||
catch (Exception ex) | ||
{ | ||
// Console.WriteLine($"An error occurred while handling FriendRequestSent: {ex.Message}"); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters