Skip to content

Commit

Permalink
(#411) comments: uopdate add like events handler
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintAngeLs committed Sep 7, 2024
1 parent f41f4ab commit 8095c79
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using MiniSpace.Services.Comments.Application.Services.Clients;
using MiniSpace.Services.Comments.Core.Entities;
using MiniSpace.Services.Comments.Core.Repositories;
using MiniSpace.Services.Comments.Core.Exceptions;
using MiniSpace.Services.Comments.Application.Services;
using System.Text.Json;

Expand Down Expand Up @@ -43,8 +42,9 @@ public AddLikeHandler(

public async Task HandleAsync(AddLike command, CancellationToken cancellationToken = default)
{
var commandJson = JsonSerializer.Serialize(command, new JsonSerializerOptions { WriteIndented = true });
var commandJson = JsonSerializer.Serialize(command, new JsonSerializerOptions { WriteIndented = true });
Console.WriteLine($"Received AddLike command: {commandJson}");

var identity = _appContext.Identity;

if (!identity.IsAuthenticated || identity.Id != command.UserId)
Expand Down Expand Up @@ -72,7 +72,12 @@ public async Task HandleAsync(AddLike command, CancellationToken cancellationTok
comment.Like(command.UserId);
await UpdateCommentAsync(comment, commentContext);

await _messageBroker.PublishAsync(new CommentUpdated(command.CommentId));
await _messageBroker.PublishAsync(new LikeAdded(
commentId: command.CommentId,
userId: command.UserId,
commentContext: command.CommentContext,
likedAt: DateTime.UtcNow
));
}

private async Task<Comment> GetCommentAsync(Guid commentId, CommentContext context)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Convey.CQRS.Events;
using System;

namespace MiniSpace.Services.Comments.Application.Events
{
public class LikeAdded : IEvent
{
public Guid CommentId { get; }
public Guid UserId { get; }
public string CommentContext { get; }
public DateTime LikedAt { get; }

public LikeAdded(Guid commentId, Guid userId, string commentContext, DateTime likedAt)
{
CommentId = commentId;
UserId = userId;
CommentContext = commentContext;
LikedAt = likedAt;
}
}
}

0 comments on commit 8095c79

Please sign in to comment.