refactor post reactions

This commit is contained in:
john 2025-08-10 18:12:16 +02:00
parent 2519fc77d2
commit 5379d29c5f
13 changed files with 129 additions and 97 deletions

View file

@ -0,0 +1,3 @@
namespace Femto.Api.Controllers.Posts.Dto;
public record GetPostResponse(PostDto Post);

View file

@ -3,4 +3,4 @@ using JetBrains.Annotations;
namespace Femto.Api.Controllers.Posts.Dto;
[PublicAPI]
public record LoadPostsResponse(IEnumerable<PostDto> Posts, Guid? Next);
public record LoadPostsResponse(IEnumerable<PostDto> Posts);

View file

@ -11,4 +11,16 @@ public record PostDto(
IEnumerable<PostReactionDto> Reactions,
DateTimeOffset CreatedAt,
IEnumerable<string> PossibleReactions
);
)
{
public static PostDto FromModel(Modules.Blog.Application.Queries.GetPosts.Dto.PostDto post) =>
new(
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.AuthorName, r.ReactedOn)),
post.CreatedAt,
post.PossibleReactions
);
}

View file

@ -1,3 +1,3 @@
namespace Femto.Api.Controllers.Posts.Dto;
public record PostReactionDto(string Emoji, int Count, bool DidReact);
public record PostReactionDto(string Emoji, string AuthorName, DateTimeOffset ReactedOn);