21 lines
620 B
C#
21 lines
620 B
C#
using Femto.Modules.Blog.Data;
|
|
using MediatR;
|
|
|
|
namespace Femto.Modules.Blog.Domain.Posts.Commands.CreatePost;
|
|
|
|
internal class CreatePostCommandHandler(BlogContext context)
|
|
: IRequestHandler<CreatePostCommand, Guid>
|
|
{
|
|
public async Task<Guid> Handle(CreatePostCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var post = new Post(
|
|
request.AuthorId,
|
|
request.Content,
|
|
request.Media.Select((url, idx) => new PostMedia(Guid.CreateVersion7(), url, idx)).ToList()
|
|
);
|
|
|
|
await context.AddAsync(post, cancellationToken);
|
|
|
|
return post.Id;
|
|
}
|
|
}
|