Implemented basic endpoints
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using PostFundManagement.Domain.Abstractions;
|
||||
using PostFundManagement.Domain.Api;
|
||||
using PostFundManagement.Domain.Extensions;
|
||||
using PostFundManagement.Infrastructure.Database;
|
||||
|
||||
namespace PostFundManagement.Api.Endpoints.Execution;
|
||||
|
||||
[ApiVersionTarget(1)]
|
||||
public class GetProjectRisksEndpoint : IEndpoint
|
||||
{
|
||||
public void Map(IEndpointRouteBuilder builder)
|
||||
{
|
||||
builder.MapGet("api/execution/risks/project/{projectId:long}", async (long projectId,
|
||||
IDbContextFactory<ApplicationDbContext> contextFactory, CancellationToken cancellationToken = default) =>
|
||||
{
|
||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||
|
||||
var risks = await context.Risks.AsNoTracking()
|
||||
.Where(r => r.ProjectId == projectId)
|
||||
.OrderByDescending(r => r.CreatedAt)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return Results.Ok(risks);
|
||||
})
|
||||
.RequireAuthorization()
|
||||
.WithDescription("Get a list of risks for a project")
|
||||
.WithName(typeof(GetProjectRisksEndpoint).ToEndpointName())
|
||||
.MapToApiVersion(new ApiVersion(1))
|
||||
.Produces(StatusCodes.Status200OK)
|
||||
.Produces(StatusCodes.Status401Unauthorized)
|
||||
.WithTags(EndpointTags.Execution);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user