stuff
This commit is contained in:
parent
ab2e20f7e1
commit
befaa207d7
23 changed files with 244 additions and 95 deletions
|
@ -1,5 +1,6 @@
|
|||
using Femto.Api.Controllers.Posts.Dto;
|
||||
using Femto.Modules.Blog.Domain.Posts.Commands.CreatePost;
|
||||
using Femto.Modules.Blog.Domain.Posts.Commands.GetPosts;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
|
@ -9,6 +10,33 @@ namespace Femto.Api.Controllers.Posts;
|
|||
[Route("posts")]
|
||||
public class PostsController(IMediator mediator) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<GetAllPublicPostsResponse>> GetAllPublicPosts(
|
||||
[FromQuery] GetPublicPostsSearchParams searchParams,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var res = await mediator.Send(
|
||||
new GetPostsQuery
|
||||
{
|
||||
From = searchParams.From,
|
||||
Amount = searchParams.Amount ?? 20
|
||||
},
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new GetAllPublicPostsResponse(
|
||||
res.Posts.Select(p => new PublicPostDto(
|
||||
new PublicPostAuthorDto(p.Author.AuthorId, p.Author.Username),
|
||||
p.PostId,
|
||||
p.Text,
|
||||
p.Media.Select(m => m.Url),
|
||||
p.CreatedAt
|
||||
)),
|
||||
res.Next
|
||||
);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<CreatePostResponse>> Post(
|
||||
[FromBody] CreatePostRequest req,
|
||||
|
@ -19,7 +47,7 @@ public class PostsController(IMediator mediator) : ControllerBase
|
|||
new CreatePostCommand(req.AuthorId, req.Content, req.Media),
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
|
||||
return new CreatePostResponse(guid);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue