load with public flag

This commit is contained in:
john 2025-05-18 13:40:05 +02:00
parent e3c95eb109
commit 322dd01ee0
14 changed files with 73 additions and 38 deletions

View file

@ -1,4 +1,5 @@
using Femto.Api.Controllers.Posts.Dto;
using Femto.Common;
using Femto.Modules.Blog.Application;
using Femto.Modules.Blog.Application.Commands.CreatePost;
using Femto.Modules.Blog.Application.Queries.GetPosts;
@ -9,17 +10,16 @@ namespace Femto.Api.Controllers.Posts;
[ApiController]
[Route("posts")]
public class PostsController(IBlogModule blogModule) : ControllerBase
public class PostsController(IBlogModule blogModule, ICurrentUserContext currentUserContext) : ControllerBase
{
[HttpGet]
[Authorize]
public async Task<ActionResult<GetAllPublicPostsResponse>> GetAllPublicPosts(
public async Task<ActionResult<GetAllPublicPostsResponse>> LoadPosts(
[FromQuery] GetPublicPostsSearchParams searchParams,
CancellationToken cancellationToken
)
{
var res = await blogModule.PostQuery(
new GetPostsQuery
new GetPostsQuery(currentUserContext.CurrentUser?.Id)
{
From = searchParams.From,
Amount = searchParams.Amount ?? 20,
@ -30,11 +30,11 @@ public class PostsController(IBlogModule blogModule) : ControllerBase
);
return new GetAllPublicPostsResponse(
res.Posts.Select(p => new PublicPostDto(
new PublicPostAuthorDto(p.Author.AuthorId, p.Author.Username),
res.Posts.Select(p => new PostDto(
new PostAuthorDto(p.Author.AuthorId, p.Author.Username),
p.PostId,
p.Text,
p.Media.Select(m => new PublicPostMediaDto(m.Url, m.Width, m.Height)),
p.Media.Select(m => new PostMediaDto(m.Url, m.Width, m.Height)),
p.CreatedAt
)),
res.Next
@ -43,7 +43,7 @@ public class PostsController(IBlogModule blogModule) : ControllerBase
[HttpPost]
[Authorize]
public async Task<ActionResult<CreatePostResponse>> Post(
public async Task<ActionResult<CreatePostResponse>> CreatePost(
[FromBody] CreatePostRequest req,
CancellationToken cancellationToken
)
@ -62,7 +62,8 @@ public class PostsController(IBlogModule blogModule) : ControllerBase
media.Width,
media.Height
)
)
),
req.IsPublic
),
cancellationToken
);