using PostFundManagement.Domain.Abstractions; using PostFundManagement.Domain.Api; using PostFundManagement.Domain.Extensions; using PostFundManagement.Infrastructure.Database; namespace PostFundManagement.Api.Endpoints.Governance; [ApiVersionTarget(1)] public class GetOrganisationByIdEndpoint : IEndpoint { public void Map(IEndpointRouteBuilder builder) { builder.MapGet("api/governance/organisations/{id:long}", async (long id, IDbContextFactory contextFactory, CancellationToken cancellationToken = default) => { using var context = await contextFactory.CreateDbContextAsync(cancellationToken); var organisation = await context.Organisations.AsNoTracking().FirstOrDefaultAsync(o => o.Id == id, cancellationToken); return organisation != null ? Results.Ok(organisation) : Results.NotFound(); }) .RequireAuthorization() .WithDescription("Get organization profile by ID") .WithName(typeof(GetOrganisationByIdEndpoint).ToEndpointName()) .MapToApiVersion(new ApiVersion(1)) .Produces(StatusCodes.Status200OK) .Produces(StatusCodes.Status404NotFound) .Produces(StatusCodes.Status401Unauthorized) .WithTags(EndpointTags.Governance); } }