This commit is contained in:
john 2025-08-10 19:57:47 +02:00
parent cbf67bf5f1
commit ce3888f1ab
15 changed files with 162 additions and 21 deletions

View file

@ -0,0 +1,5 @@
using Femto.Common.Domain;
namespace Femto.Modules.Blog.Application.Commands.AddPostComment;
public record AddPostCommentCommand(Guid PostId, Guid AuthorId, string Content) : ICommand;

View file

@ -0,0 +1,20 @@
using Femto.Common.Domain;
using Microsoft.EntityFrameworkCore;
namespace Femto.Modules.Blog.Application.Commands.AddPostComment;
internal class AddPostCommentCommandHandler(BlogContext context) : ICommandHandler<AddPostCommentCommand>
{
public async Task Handle(AddPostCommentCommand request, CancellationToken cancellationToken)
{
var post = await context.Posts.SingleOrDefaultAsync(
p => p.Id == request.PostId,
cancellationToken
);
if (post is null)
return;
post.AddComment(request.AuthorId, request.Content);
}
}

View file

@ -24,11 +24,9 @@ internal class CreatePostCommandHandler(BlogContext context)
media.Width,
media.Height
))
.ToList()
)
{
IsPublic = request.IsPublic is true
};
.ToList(),
request.IsPublic is true
);
await context.AddAsync(post, cancellationToken);
@ -39,7 +37,8 @@ internal class CreatePostCommandHandler(BlogContext context)
post.PostedOn,
new PostAuthorDto(post.AuthorId, request.CurrentUser.Username),
[],
post.PossibleReactions
post.PossibleReactions,
[]
);
}
}