load with public flag
This commit is contained in:
parent
e3c95eb109
commit
322dd01ee0
14 changed files with 73 additions and 38 deletions
|
@ -17,6 +17,10 @@ public class GetPostsQueryHandler(IDbConnectionFactory connectionFactory)
|
|||
|
||||
var orderBy = query.Direction is GetPostsDirection.Backward ? "desc" : "asc";
|
||||
var pageFilter = query.Direction is GetPostsDirection.Backward ? "<=" : ">=";
|
||||
var username = query.Author;
|
||||
var authorGuid = query.AuthorId;
|
||||
var cursor = query.From;
|
||||
var showPrivate = query.CurrentUserId is not null;
|
||||
|
||||
// lang=sql
|
||||
var sql = $$"""
|
||||
|
@ -25,6 +29,7 @@ public class GetPostsQueryHandler(IDbConnectionFactory connectionFactory)
|
|||
from blog.post
|
||||
inner join blog.author on blog.author.id = blog.post.author_id
|
||||
where (@username is null or blog.author.username = @username)
|
||||
and (@showPrivate or blog.post.is_public = true)
|
||||
and (@authorGuid is null or blog.author.id = @authorGuid)
|
||||
and (@cursor is null or blog.post.id {{pageFilter}} @cursor)
|
||||
order by blog.post.id {{orderBy}}
|
||||
|
@ -48,11 +53,12 @@ public class GetPostsQueryHandler(IDbConnectionFactory connectionFactory)
|
|||
sql,
|
||||
new
|
||||
{
|
||||
username = query.Author,
|
||||
authorGuid = query.AuthorId,
|
||||
cursor = query.From,
|
||||
// load an extra one to take for the curst
|
||||
username,
|
||||
authorGuid,
|
||||
cursor,
|
||||
// load an extra one to take for the cursor
|
||||
amount = query.Amount + 1,
|
||||
showPrivate,
|
||||
}
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue