using PostFundManagement.Application.Extensions; using PostFundManagement.Application.Services.Projects; using PostFundManagement.Domain.Abstractions; using PostFundManagement.Domain.Errors; using PostFundManagement.Domain.Extensions; using PostFundManagement.Domain.Models; using PostFundManagement.Domain.Security; using Problems = Microsoft.AspNetCore.Mvc.ProblemDetails; namespace PostFundManagement.Api.Endpoints.Projects; [ApiVersionTarget(1)] public class GetProjectIndicatorsEndpoint : IEndpoint { public void Map(IEndpointRouteBuilder builder) { builder.MapGet("api/projects/indicators/project/{projectId}", async (string projectId, ProjectService service, CancellationToken cancellationToken = default) => await service.GetProjectIndicatorsAsync(projectIdHash: projectId, cancellationToken) switch { { IsSuccess: true, Value: var indicators } => Results.Ok(indicators), var r when r.HasError() => Results.Forbid(), var r => Results.InternalServerError(r.Errors.ToProblems()) }) .WithDescription("Get get a detailed list of project indicators") .WithName(typeof(GetProjectIndicatorsEndpoint).ToEndpointName()) .MapToApiVersion(new ApiVersion(1)) .Produces(StatusCodes.Status200OK) .Produces(StatusCodes.Status404NotFound) .Produces(StatusCodes.Status403Forbidden) .Produces(StatusCodes.Status401Unauthorized) .Produces(StatusCodes.Status500InternalServerError) .WithTags(EndpointTags.Projects); } }