using PostFundManagement.Application.Abstractions.Services; using PostFundManagement.Application.Extensions; using PostFundManagement.Domain; using PostFundManagement.Domain.Abstractions; using PostFundManagement.Domain.Extensions; using PostFundManagement.Domain.Models; namespace PostFundManagement.Api.Endpoints.Grants; [ApiVersionTarget(1)] public class GetAwardsEndpoint : IEndpoint { public void Map(IEndpointRouteBuilder builder) { builder.MapGet("api/grants/awards", async (IGrantsService service, int page = 1, int pageSize = 10, CancellationToken cancellationToken = default) => await service.GetAwardsAsync(Pagination.Create(page, pageSize), cancellationToken) switch { { IsSuccess: true, Value: var awards } => Results.Ok(awards), var r => Results.InternalServerError(r.Errors.ToProblems()) }) .WithDescription("Get a list of awards") .RequireAuthorization(Constants.MainScope) .WithName(typeof(GetAwardsEndpoint).ToEndpointName()) .MapToApiVersion(new ApiVersion(1)) .Produces(StatusCodes.Status200OK) .Produces(StatusCodes.Status500InternalServerError) .Produces(StatusCodes.Status401Unauthorized) .WithTags(EndpointTags.Grants) .CacheOutput(); } }