return postdto from post create
This commit is contained in:
parent
8ad4302ec8
commit
d1687f276b
15 changed files with 226 additions and 111 deletions
|
@ -1,8 +1,22 @@
|
|||
using Femto.Common;
|
||||
using Femto.Common.Domain;
|
||||
using Femto.Modules.Blog.Application.Queries.GetPosts.Dto;
|
||||
|
||||
namespace Femto.Modules.Blog.Application.Commands.CreatePost;
|
||||
|
||||
public record CreatePostCommand(Guid AuthorId, string Content, IEnumerable<CreatePostMedia> Media, bool? IsPublic)
|
||||
: ICommand<Guid>;
|
||||
public record CreatePostCommand(
|
||||
Guid AuthorId,
|
||||
string Content,
|
||||
IEnumerable<CreatePostMedia> Media,
|
||||
bool? IsPublic,
|
||||
CurrentUser CurrentUser
|
||||
) : ICommand<PostDto>;
|
||||
|
||||
public record CreatePostMedia(Guid MediaId, Uri Url, string? Type, int Order, int? Width, int? Height);
|
||||
public record CreatePostMedia(
|
||||
Guid MediaId,
|
||||
Uri Url,
|
||||
string? Type,
|
||||
int Order,
|
||||
int? Width,
|
||||
int? Height
|
||||
);
|
||||
|
|
|
@ -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