load with public flag
This commit is contained in:
parent
e3c95eb109
commit
322dd01ee0
14 changed files with 73 additions and 38 deletions
|
@ -2,7 +2,7 @@ using Femto.Common.Domain;
|
|||
|
||||
namespace Femto.Modules.Blog.Application.Commands.CreatePost;
|
||||
|
||||
public record CreatePostCommand(Guid AuthorId, string Content, IEnumerable<CreatePostMedia> Media)
|
||||
public record CreatePostCommand(Guid AuthorId, string Content, IEnumerable<CreatePostMedia> Media, bool? IsPublic)
|
||||
: ICommand<Guid>;
|
||||
|
||||
public record CreatePostMedia(Guid MediaId, Uri Url, string? Type, int Order, int? Width, int? Height);
|
||||
|
|
|
@ -22,6 +22,8 @@ internal class CreatePostCommandHandler(BlogContext context)
|
|||
))
|
||||
.ToList()
|
||||
);
|
||||
|
||||
post.IsPublic = request.IsPublic is true;
|
||||
|
||||
await context.AddAsync(post, cancellationToken);
|
||||
|
||||
|
|
|
@ -3,23 +3,22 @@ using Femto.Modules.Blog.Application.Queries.GetPosts.Dto;
|
|||
|
||||
namespace Femto.Modules.Blog.Application.Queries.GetPosts;
|
||||
|
||||
public class GetPostsQuery : IQuery<GetPostsQueryResult>
|
||||
public record GetPostsQuery(Guid? CurrentUserId) : IQuery<GetPostsQueryResult>
|
||||
{
|
||||
public Guid? From { get; init; }
|
||||
public int Amount { get; init; } = 20;
|
||||
public Guid? AuthorId { get; init; }
|
||||
public string? Author { get; set; }
|
||||
|
||||
public string? Author { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Default is to load in reverse chronological order
|
||||
/// TODO this is not exposed on the client as it probably wouldn't work that well
|
||||
/// </summary>
|
||||
public GetPostsDirection Direction { get; init; } = GetPostsDirection.Backward;
|
||||
|
||||
}
|
||||
|
||||
public enum GetPostsDirection
|
||||
{
|
||||
Forward,
|
||||
Backward
|
||||
}
|
||||
Backward,
|
||||
}
|
||||
|
|
|
@ -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