using PostFundManagement.Application.Abstractions.Services; using PostFundManagement.Application.Extensions; using PostFundManagement.Domain.Abstractions; using PostFundManagement.Domain.Errors; using PostFundManagement.Domain.Extensions; using PostFundManagement.Domain.Security; using Problems = Microsoft.AspNetCore.Mvc.ProblemDetails; namespace PostFundManagement.Api.Endpoints.Evidence; [ApiVersionTarget(1)] public class GetProjectEvidenceEndpoint : IEndpoint { public void Map(IEndpointRouteBuilder builder) { builder.MapGet("api/evidence/{projectId}", async (string projectId, IEvidenceService service, CancellationToken cancellationToken = default) => await service.GetProjectEvidencesAsync(projectId, cancellationToken) switch { { IsSuccess: true, Value: var evidence } => Results.Ok(evidence), var r when r.HasError() => Results.Forbid(), var r => Results.InternalServerError(r.Errors.ToProblems()), }) .WithDescription("Get a list of all uploaded evidence metadata for a specific project") .RequireAuthorization(Constants.MainScope) .WithName(typeof(GetProjectEvidenceEndpoint).ToEndpointName()) .MapToApiVersion(new ApiVersion(1)) .Produces(StatusCodes.Status200OK) .Produces(StatusCodes.Status404NotFound) .Produces(StatusCodes.Status401Unauthorized) .Produces(StatusCodes.Status403Forbidden) .Produces(StatusCodes.Status500InternalServerError) .WithTags(EndpointTags.Evidence) .CacheOutput(); } }