femto-backend/Femto.Api/Controllers/Authors/AuthorsController.cs
2025-05-03 15:38:57 +02:00

28 lines
878 B
C#

using Femto.Api.Controllers.Authors.Dto;
using Femto.Modules.Blog.Domain.Posts.Commands.GetAuthorPosts;
using MediatR;
using Microsoft.AspNetCore.Mvc;
namespace Femto.Api.Controllers.Authors;
[ApiController]
[Route("authors")]
public class AuthorsController(IMediator mediator) : ControllerBase
{
[HttpGet("{authorId}/posts")]
public async Task<ActionResult<GetAuthorPostsResponse>> GetAuthorPosts(
Guid authorId,
[FromQuery] GetAuthorPostsSearchParams searchParams,
CancellationToken cancellationToken
)
{
var posts = await mediator.Send(
new GetAuthorPostsQuery(authorId, searchParams.Cursor, searchParams.Count),
cancellationToken
);
return new GetAuthorPostsResponse(
posts.Select(p => new AuthorPostDto(p.PostId, p.Text, p.Media.Select(m => m.Url)))
);
}
}