Skip to content

Commit

Permalink
(#411) comments: update comment udpate command handler
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintAngeLs committed Sep 15, 2024
1 parent a05dcd5 commit f84de45
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using MiniSpace.Services.Comments.Application.Services;
using MiniSpace.Services.Comments.Core.Entities;
using MiniSpace.Services.Comments.Core.Repositories;
using MiniSpace.Services.Comments.Application.Services.Clients;

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

public UpdateCommentHandler(
IOrganizationEventsCommentRepository organizationEventsCommentRepository,
Expand All @@ -27,7 +29,8 @@ public UpdateCommentHandler(
IUserPostsCommentRepository userPostsCommentRepository,
IAppContext appContext,
IMessageBroker messageBroker,
IDateTimeProvider dateTimeProvider)
IDateTimeProvider dateTimeProvider,
IStudentsServiceClient userServiceClient)
{
_organizationEventsCommentRepository = organizationEventsCommentRepository;
_organizationPostsCommentRepository = organizationPostsCommentRepository;
Expand All @@ -36,6 +39,7 @@ public UpdateCommentHandler(
_appContext = appContext;
_messageBroker = messageBroker;
_dateTimeProvider = dateTimeProvider;
_userServiceClient = userServiceClient;
}

public async Task HandleAsync(UpdateComment command, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -83,26 +87,31 @@ public async Task HandleAsync(UpdateComment command, CancellationToken cancellat
case nameof(CommentContext.OrganizationEvent):
await _organizationEventsCommentRepository.UpdateAsync(comment);
break;

case nameof(CommentContext.OrganizationPost):
await _organizationPostsCommentRepository.UpdateAsync(comment);
break;

case nameof(CommentContext.UserEvent):
await _userEventsCommentRepository.UpdateAsync(comment);
break;

case nameof(CommentContext.UserPost):
await _userPostsCommentRepository.UpdateAsync(comment);
break;
}

var user = await _userServiceClient.GetAsync(identity.Id);
if (user == null)
{
throw new UserNotFoundException(identity.Id);
}

await _messageBroker.PublishAsync(new CommentUpdated(
commentId: command.CommentId,
userId: identity.Id,
commentContext: command.CommentContext,
updatedAt: _dateTimeProvider.Now,
commentContent: command.TextContent
commentContent: command.TextContent,
userName: $"{user.FirstName} {user.LastName}",
profileImageUrl: user.ProfileImageUrl
));
}
}
Expand Down

0 comments on commit f84de45

Please sign in to comment.