wip comments
This commit is contained in:
parent
cbf67bf5f1
commit
4c69c6d30d
14 changed files with 151 additions and 21 deletions
|
@ -68,7 +68,7 @@ public class GetPostsQueryHandler(IDbConnectionFactory connectionFactory)
|
|||
""",
|
||||
new { postIds }
|
||||
);
|
||||
|
||||
|
||||
var media = loadMediaResult.ToList();
|
||||
|
||||
var loadReactionsResult = await conn.QueryAsync<LoadReactionRow>(
|
||||
|
@ -87,16 +87,36 @@ public class GetPostsQueryHandler(IDbConnectionFactory connectionFactory)
|
|||
|
||||
var reactions = loadReactionsResult.ToList();
|
||||
|
||||
var loadCommentsResult = await conn.QueryAsync<LoadCommentRow>(
|
||||
"""
|
||||
select
|
||||
pc.id as CommentId,
|
||||
pc.post_id as PostId,
|
||||
pc.content as Content,
|
||||
pc.created_at as PostedOn,
|
||||
a.username as AuthorName
|
||||
from blog.post_comment pc
|
||||
join blog.author a on pc.author_id = a.id
|
||||
where pc.post_id = ANY (@postIds)
|
||||
""",
|
||||
new { postIds }
|
||||
);
|
||||
|
||||
var comments = loadCommentsResult.ToList();
|
||||
|
||||
return new GetPostsQueryResult(
|
||||
posts
|
||||
.Select(p => new PostDto(
|
||||
p.PostId,
|
||||
p.Content,
|
||||
media.Where(m => m.PostId == p.PostId).Select(m => new PostMediaDto(
|
||||
new Uri(m.MediaUrl),
|
||||
m.MediaWidth,
|
||||
m.MediaHeight
|
||||
)).ToList(),
|
||||
media
|
||||
.Where(m => m.PostId == p.PostId)
|
||||
.Select(m => new PostMediaDto(
|
||||
new Uri(m.MediaUrl),
|
||||
m.MediaWidth,
|
||||
m.MediaHeight
|
||||
))
|
||||
.ToList(),
|
||||
p.PostedOn,
|
||||
new PostAuthorDto(p.AuthorId, p.Username),
|
||||
reactions
|
||||
|
@ -105,7 +125,11 @@ public class GetPostsQueryHandler(IDbConnectionFactory connectionFactory)
|
|||
.ToList(),
|
||||
!string.IsNullOrEmpty(p.PossibleReactions)
|
||||
? JsonSerializer.Deserialize<IEnumerable<string>>(p.PossibleReactions)!
|
||||
: []
|
||||
: [],
|
||||
comments
|
||||
.Where(c => c.PostId == p.PostId)
|
||||
.Select(c => new PostCommentDto(c.AuthorName, c.Content, c.PostedOn))
|
||||
.ToList()
|
||||
))
|
||||
.ToList()
|
||||
);
|
||||
|
@ -137,4 +161,13 @@ public class GetPostsQueryHandler(IDbConnectionFactory connectionFactory)
|
|||
public string Emoji { get; init; }
|
||||
public DateTimeOffset CreatedAt { get; init; }
|
||||
}
|
||||
|
||||
internal record LoadCommentRow
|
||||
{
|
||||
public Guid CommentId { get; init; }
|
||||
public Guid PostId { get; init; }
|
||||
public string Content { get; init; }
|
||||
public DateTimeOffset PostedOn { get; init; }
|
||||
public string AuthorName { get; init; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue