diff --git a/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Commands/Handlers/DeleteCommentHandler.cs b/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Commands/Handlers/DeleteCommentHandler.cs index c4fc5e79a..788dd0e3d 100644 --- a/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Commands/Handlers/DeleteCommentHandler.cs +++ b/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Commands/Handlers/DeleteCommentHandler.cs @@ -94,7 +94,7 @@ public async Task HandleAsync(DeleteComment command, CancellationToken cancellat break; } - await _messageBroker.PublishAsync(new CommentDeleted(command.CommentId)); + // await _messageBroker.PublishAsync(new CommentDeleted(command.CommentId)); } } } diff --git a/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Commands/Handlers/DeleteLikeHandler.cs b/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Commands/Handlers/DeleteLikeHandler.cs index 75d6bd4df..c31f2d3b4 100644 --- a/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Commands/Handlers/DeleteLikeHandler.cs +++ b/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Commands/Handlers/DeleteLikeHandler.cs @@ -42,7 +42,7 @@ public async Task HandleAsync(DeleteLike command, CancellationToken cancellation comment.UnLike(identity.Id); await _commentRepository.UpdateAsync(comment); - await _messageBroker.PublishAsync(new CommentUpdated(command.CommentId)); + // await _messageBroker.PublishAsync(new CommentUpdated(command.CommentId)); } } } diff --git a/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Commands/Handlers/UpdateCommentHandler.cs b/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Commands/Handlers/UpdateCommentHandler.cs index 5f986c966..c0462ef13 100644 --- a/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Commands/Handlers/UpdateCommentHandler.cs +++ b/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Commands/Handlers/UpdateCommentHandler.cs @@ -64,12 +64,13 @@ public async Task HandleAsync(UpdateComment command, CancellationToken cancellat throw new InvalidCommentContextEnumException(command.CommentContext); } - if (comment is null) + if (comment == null) { throw new CommentNotFoundException(command.CommentId); } var identity = _appContext.Identity; + if (identity.IsAuthenticated && identity.Id != comment.UserId) { throw new UnauthorizedCommentAccessException(command.CommentId, identity.Id); @@ -96,7 +97,13 @@ public async Task HandleAsync(UpdateComment command, CancellationToken cancellat break; } - await _messageBroker.PublishAsync(new CommentUpdated(command.CommentId)); + await _messageBroker.PublishAsync(new CommentUpdated( + commentId: command.CommentId, + userId: identity.Id, + commentContext: command.CommentContext, + updatedAt: _dateTimeProvider.Now, + commentContent: command.TextContent + )); } } } diff --git a/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Events/CommentUpdated.cs b/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Events/CommentUpdated.cs index 360c41cc1..366e47f6c 100644 --- a/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Events/CommentUpdated.cs +++ b/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Events/CommentUpdated.cs @@ -6,10 +6,18 @@ namespace MiniSpace.Services.Comments.Application.Events public class CommentUpdated : IEvent { public Guid CommentId { get; } + public Guid UserId { get; } + public string CommentContext { get; } + public DateTime UpdatedAt { get; } + public string CommentContent { get; } - public CommentUpdated(Guid commentId) + public CommentUpdated(Guid commentId, Guid userId, string commentContext, DateTime updatedAt, string commentContent) { CommentId = commentId; + UserId = userId; + CommentContext = commentContext; + UpdatedAt = updatedAt; + CommentContent = commentContent; } } } diff --git a/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Events/LikeUpdated.cs b/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Events/LikeUpdated.cs index 076cee7e2..6d294e3bb 100644 --- a/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Events/LikeUpdated.cs +++ b/MiniSpace.Services.Comments/src/MiniSpace.Services.Comments.Application/Events/LikeUpdated.cs @@ -2,17 +2,24 @@ using System; using System.Diagnostics.CodeAnalysis; - namespace MiniSpace.Services.Comments.Application.Events { [ExcludeFromCodeCoverage] public class LikeUpdated : IEvent { public Guid CommentId { get; } + public Guid UserId { get; } + public string CommentContext { get; } + public DateTime UpdatedAt { get; } + public string CommentContent { get; } - public LikeUpdated(Guid commentId) + public LikeUpdated(Guid commentId, Guid userId, string commentContext, DateTime updatedAt, string commentContent) { CommentId = commentId; + UserId = userId; + CommentContext = commentContext; + UpdatedAt = updatedAt; + CommentContent = commentContent; } } }