using Femto.Common.Domain;
using Microsoft.EntityFrameworkCore;

namespace Femto.Modules.Blog.Application.Commands.AddPostReaction;

internal class AddPostReactionCommandHandler(BlogContext context)
    : ICommandHandler<AddPostReactionCommand>
{
    public async Task Handle(AddPostReactionCommand request, CancellationToken cancellationToken)
    {
        var post = await context.Posts.SingleOrDefaultAsync(
            p => p.Id == request.PostId,
            cancellationToken
        );

        if (post is null)
            return;

        post.AddReaction(request.ReactorId, request.Emoji);
    }
}
