Skip to content

Commit

Permalink
(#411) commets: update update comment event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintAngeLs committed Sep 7, 2024
1 parent c555588 commit f41f4ab
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit f41f4ab

Please sign in to comment.