return postdto from post create
This commit is contained in:
parent
8ad4302ec8
commit
d1687f276b
15 changed files with 226 additions and 111 deletions
|
@ -1,3 +1,3 @@
|
|||
namespace Femto.Api.Controllers.Posts.Dto;
|
||||
|
||||
public record CreatePostResponse(Guid PostId);
|
||||
public record CreatePostResponse(PostDto Post);
|
|
@ -9,5 +9,6 @@ public record PostDto(
|
|||
string Content,
|
||||
IEnumerable<PostMediaDto> Media,
|
||||
IEnumerable<PostReactionDto> Reactions,
|
||||
DateTimeOffset CreatedAt
|
||||
DateTimeOffset CreatedAt,
|
||||
IEnumerable<string> PossibleReactions
|
||||
);
|
|
@ -1,3 +1,3 @@
|
|||
namespace Femto.Api.Controllers.Posts.Dto;
|
||||
|
||||
public record PostReactionDto(Guid ReactionId, string Emoji, int Count, bool DidReact);
|
||||
public record PostReactionDto(string Emoji, int Count, bool DidReact);
|
|
@ -11,7 +11,8 @@ namespace Femto.Api.Controllers.Posts;
|
|||
|
||||
[ApiController]
|
||||
[Route("posts")]
|
||||
public class PostsController(IBlogModule blogModule, ICurrentUserContext currentUserContext) : ControllerBase
|
||||
public class PostsController(IBlogModule blogModule, ICurrentUserContext currentUserContext)
|
||||
: ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<LoadPostsResponse>> LoadPosts(
|
||||
|
@ -36,8 +37,9 @@ public class PostsController(IBlogModule blogModule, ICurrentUserContext current
|
|||
p.PostId,
|
||||
p.Text,
|
||||
p.Media.Select(m => new PostMediaDto(m.Url, m.Width, m.Height)),
|
||||
p.Reactions?.Select(r => new PostReactionDto(r.ReactionId, r.Emoji, r.Count, r.DidReact)),
|
||||
p.CreatedAt
|
||||
p.Reactions.Select(r => new PostReactionDto(r.Emoji, r.Count, r.DidReact)),
|
||||
p.CreatedAt,
|
||||
p.PossibleReactions
|
||||
)),
|
||||
res.Next
|
||||
);
|
||||
|
@ -50,7 +52,7 @@ public class PostsController(IBlogModule blogModule, ICurrentUserContext current
|
|||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var guid = await blogModule.Command(
|
||||
var post = await blogModule.Command(
|
||||
new CreatePostCommand(
|
||||
req.AuthorId,
|
||||
req.Content,
|
||||
|
@ -65,18 +67,32 @@ public class PostsController(IBlogModule blogModule, ICurrentUserContext current
|
|||
media.Height
|
||||
)
|
||||
),
|
||||
req.IsPublic
|
||||
req.IsPublic,
|
||||
currentUserContext.CurrentUser!
|
||||
),
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new CreatePostResponse(guid);
|
||||
return new CreatePostResponse(
|
||||
new PostDto(
|
||||
new PostAuthorDto(post.Author.AuthorId, post.Author.Username),
|
||||
post.PostId,
|
||||
post.Text,
|
||||
post.Media.Select(m => new PostMediaDto(m.Url, m.Width, m.Height)),
|
||||
post.Reactions.Select(r => new PostReactionDto(r.Emoji, r.Count, r.DidReact)).ToList(),
|
||||
post.CreatedAt,
|
||||
post.PossibleReactions
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
[HttpDelete("{postId}")]
|
||||
[Authorize]
|
||||
public async Task DeletePost(Guid postId, CancellationToken cancellationToken)
|
||||
{
|
||||
await blogModule.Command(new DeletePostCommand(postId, currentUserContext.CurrentUser!.Id), cancellationToken);
|
||||
await blogModule.Command(
|
||||
new DeletePostCommand(postId, currentUserContext.CurrentUser!.Id),
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue