using PostFundManagement.Application.Abstractions.Services; using PostFundManagement.Application.Extensions; 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.Governance; [ApiVersionTarget(1)] public class GetOrganisationPortfoliosEndpoint : IEndpoint { public void Map(IEndpointRouteBuilder builder) { builder.MapGet("api/governance/organisations/{organisationId}/portfolio", async (string organisationId, IGovernanceService service, CancellationToken cancellationToken = default) => await service.GetOrganisationPorfoliosAsync(organisationId, cancellationToken) switch { { IsSuccess: true, Value: var portfolios } => Results.Ok(portfolios), var r when r.HasError() => Results.Forbid(), var r => Results.InternalServerError(r.Errors.ToProblems()) }) .WithDescription("Get all portfolios belonging to a specific organisation") .RequireAuthorization(Constants.MainScope) .WithName(typeof(GetOrganisationPortfoliosEndpoint).ToEndpointName()) .MapToApiVersion(new ApiVersion(1)) .Produces(StatusCodes.Status200OK) .Produces(StatusCodes.Status403Forbidden) .Produces(StatusCodes.Status401Unauthorized) .Produces(StatusCodes.Status500InternalServerError) .WithTags(EndpointTags.Governance) .CacheOutput(); } }