40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using Femto.Api.Controllers.Authors.Dto;
|
|
using Femto.Modules.Blog.Domain.Posts.Commands.GetPosts;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Femto.Api.Controllers.Authors;
|
|
|
|
[ApiController]
|
|
[Route("authors")]
|
|
public class AuthorsController(IMediator mediator) : ControllerBase
|
|
{
|
|
[HttpGet("{username}/posts")]
|
|
public async Task<ActionResult<GetAuthorPostsResponse>> GetAuthorPosts(
|
|
string username,
|
|
[FromQuery] GetAuthorPostsSearchParams searchParams,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var res = await mediator.Send(
|
|
new GetPostsQuery
|
|
{
|
|
Username = username,
|
|
Amount = searchParams.Amount ?? 20,
|
|
From = searchParams.From,
|
|
},
|
|
cancellationToken
|
|
);
|
|
|
|
return new GetAuthorPostsResponse(
|
|
res.Posts.Select(p => new AuthorPostDto(
|
|
p.PostId,
|
|
p.Text,
|
|
p.Media.Select(m => m.Url),
|
|
p.CreatedAt,
|
|
new AuthoPostAuthorDto(p.Author.AuthorId, p.Author.Username)
|
|
)),
|
|
res.Next
|
|
);
|
|
}
|
|
}
|