return postdto from post create
This commit is contained in:
parent
8ad4302ec8
commit
d1687f276b
15 changed files with 226 additions and 111 deletions
|
@ -1,12 +1,16 @@
|
|||
using Femto.Modules.Blog.Application.Queries.GetPosts.Dto;
|
||||
using Femto.Modules.Blog.Domain.Posts;
|
||||
using MediatR;
|
||||
|
||||
namespace Femto.Modules.Blog.Application.Commands.CreatePost;
|
||||
|
||||
internal class CreatePostCommandHandler(BlogContext context)
|
||||
: IRequestHandler<CreatePostCommand, Guid>
|
||||
: IRequestHandler<CreatePostCommand, PostDto>
|
||||
{
|
||||
public async Task<Guid> Handle(CreatePostCommand request, CancellationToken cancellationToken)
|
||||
public async Task<PostDto> Handle(
|
||||
CreatePostCommand request,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var post = new Post(
|
||||
request.AuthorId,
|
||||
|
@ -22,11 +26,19 @@ internal class CreatePostCommandHandler(BlogContext context)
|
|||
))
|
||||
.ToList()
|
||||
);
|
||||
|
||||
|
||||
post.IsPublic = request.IsPublic is true;
|
||||
|
||||
await context.AddAsync(post, cancellationToken);
|
||||
|
||||
return post.Id;
|
||||
return new PostDto(
|
||||
post.Id,
|
||||
post.Content,
|
||||
post.Media.Select(m => new PostMediaDto(m.Url, m.Width, m.Height)).ToList(),
|
||||
post.PostedOn,
|
||||
new PostAuthorDto(post.AuthorId, request.CurrentUser.Username),
|
||||
[],
|
||||
post.PossibleReactions
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue