28 lines
878 B
C#
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)))
|
|
);
|
|
}
|
|
}
|