Files
pfm/PostFundManagement.Api/Endpoints/Evidence/GetProjectMilestonesEndpoint.cs
T
2026-08-25 17:52:44 +02:00

34 lines
1.3 KiB
C#

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<ApplicationDbContext> 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);
}
}