using PostFundManagement.Application.Extensions; using PostFundManagement.Application.Services.Projects; using PostFundManagement.Domain; using PostFundManagement.Domain.Abstractions; using PostFundManagement.Domain.Extensions; using PostFundManagement.Domain.Models; using PostFundManagement.Domain.Security; namespace PostFundManagement.Api.Endpoints.Projects; [ApiVersionTarget(1)] public class GetProjectsEndpoint : IEndpoint { public void Map(IEndpointRouteBuilder builder) { builder.MapGet("api/projects", async (ProjectService service, int page = 1, int pageSize = 100, CancellationToken cancellationToken = default) => { var result = await service.GetProjectsAsync(Pagination.Create(page, pageSize), cancellationToken); return result.IsSuccess ? Results.Ok(result.Value) : Results.BadRequest(result.Errors.ToProblems()); }) .WithDescription("Get a list of projects") .WithName(typeof(GetProjectsEndpoint).ToEndpointName()) .MapToApiVersion(new ApiVersion(1)) .Produces(StatusCodes.Status200OK) .Produces(StatusCodes.Status400BadRequest) .Produces(StatusCodes.Status401Unauthorized) .WithTags(EndpointTags.Projects); } }