Skip to content

Commit f84de45

Browse files
committed
(#411) comments: update comment udpate command handler
1 parent a05dcd5 commit f84de45

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Commands/Handlers/UpdateCommentHandler.cs

+14-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using MiniSpace.Services.Comments.Application.Services;
88
using MiniSpace.Services.Comments.Core.Entities;
99
using MiniSpace.Services.Comments.Core.Repositories;
10+
using MiniSpace.Services.Comments.Application.Services.Clients;
1011

1112
namespace MiniSpace.Services.Comments.Application.Commands.Handlers
1213
{
@@ -19,6 +20,7 @@ public class UpdateCommentHandler : ICommandHandler<UpdateComment>
1920
private readonly IAppContext _appContext;
2021
private readonly IMessageBroker _messageBroker;
2122
private readonly IDateTimeProvider _dateTimeProvider;
23+
private readonly IStudentsServiceClient _userServiceClient;
2224

2325
public UpdateCommentHandler(
2426
IOrganizationEventsCommentRepository organizationEventsCommentRepository,
@@ -27,7 +29,8 @@ public UpdateCommentHandler(
2729
IUserPostsCommentRepository userPostsCommentRepository,
2830
IAppContext appContext,
2931
IMessageBroker messageBroker,
30-
IDateTimeProvider dateTimeProvider)
32+
IDateTimeProvider dateTimeProvider,
33+
IStudentsServiceClient userServiceClient)
3134
{
3235
_organizationEventsCommentRepository = organizationEventsCommentRepository;
3336
_organizationPostsCommentRepository = organizationPostsCommentRepository;
@@ -36,6 +39,7 @@ public UpdateCommentHandler(
3639
_appContext = appContext;
3740
_messageBroker = messageBroker;
3841
_dateTimeProvider = dateTimeProvider;
42+
_userServiceClient = userServiceClient;
3943
}
4044

4145
public async Task HandleAsync(UpdateComment command, CancellationToken cancellationToken = default)
@@ -83,26 +87,31 @@ public async Task HandleAsync(UpdateComment command, CancellationToken cancellat
8387
case nameof(CommentContext.OrganizationEvent):
8488
await _organizationEventsCommentRepository.UpdateAsync(comment);
8589
break;
86-
8790
case nameof(CommentContext.OrganizationPost):
8891
await _organizationPostsCommentRepository.UpdateAsync(comment);
8992
break;
90-
9193
case nameof(CommentContext.UserEvent):
9294
await _userEventsCommentRepository.UpdateAsync(comment);
9395
break;
94-
9596
case nameof(CommentContext.UserPost):
9697
await _userPostsCommentRepository.UpdateAsync(comment);
9798
break;
9899
}
99100

101+
var user = await _userServiceClient.GetAsync(identity.Id);
102+
if (user == null)
103+
{
104+
throw new UserNotFoundException(identity.Id);
105+
}
106+
100107
await _messageBroker.PublishAsync(new CommentUpdated(
101108
commentId: command.CommentId,
102109
userId: identity.Id,
103110
commentContext: command.CommentContext,
104111
updatedAt: _dateTimeProvider.Now,
105-
commentContent: command.TextContent
112+
commentContent: command.TextContent,
113+
userName: $"{user.FirstName} {user.LastName}",
114+
profileImageUrl: user.ProfileImageUrl
106115
));
107116
}
108117
}

0 commit comments

Comments
 (0)