using Application.Abstractions.Messaging;
using Web.Api.Common;

namespace Web.Api.Endpoints.News;

internal sealed class Articles : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet("api/news/articles", async (
            ISender sender,
            CancellationToken ct,
            int? rssFeedSourceID = null,
            string? keyword = null,
            int page = 1,
            ushort perPage = 20
        ) =>
        {
            var query = new Application.Features.Api.News.GetArticles.Query(rssFeedSourceID, keyword, page, perPage);

            return ApiResponse.Ok(await sender.Send(query, ct));
        })
        .WithTags("News")
        .AllowAnonymous();
    }
}