using PostFundManagement.Domain.Abstractions; using PostFundManagement.Domain.Api; using PostFundManagement.Domain.Extensions; using PostFundManagement.Infrastructure.Database; namespace PostFundManagement.Api.Endpoints.Evidence; [ApiVersionTarget(1)] public class GetProjectMilestonesEndpoint : IEndpoint { public void Map(IEndpointRouteBuilder builder) { builder.MapGet("api/evidence/milestones/project/{projectId:long}", async (long projectId, IDbContextFactory contextFactory, CancellationToken cancellationToken = default) => { using var context = await contextFactory.CreateDbContextAsync(cancellationToken); var milestones = await context.Milestones.AsNoTracking() .Where(m => m.ProjectId == projectId) .OrderBy(m => m.DueAt) .ToListAsync(cancellationToken); return Results.Ok(milestones); }) .RequireAuthorization() .WithDescription("Get a list of milestones for a project") .WithName(typeof(GetProjectMilestonesEndpoint).ToEndpointName()) .MapToApiVersion(new ApiVersion(1)) .Produces(StatusCodes.Status200OK) .Produces(StatusCodes.Status401Unauthorized) .WithTags(EndpointTags.Evidence); } }