33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
using PostFundManagement.Domain.Abstractions;
|
|
using PostFundManagement.Domain.Api;
|
|
using PostFundManagement.Domain.Extensions;
|
|
using PostFundManagement.Infrastructure.Database;
|
|
|
|
namespace PostFundManagement.Api.Endpoints.Grants;
|
|
|
|
[ApiVersionTarget(1)]
|
|
public class GetAwardByIdEndpoint : IEndpoint
|
|
{
|
|
public void Map(IEndpointRouteBuilder builder)
|
|
{
|
|
builder.MapGet("api/grants/awards/{id:long}", async (long id, IDbContextFactory<ApplicationDbContext> contextFactory,
|
|
CancellationToken cancellationToken = default) =>
|
|
{
|
|
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
|
|
|
var award = await context.Awards.AsNoTracking()
|
|
.FirstOrDefaultAsync(a => a.Id == id, cancellationToken);
|
|
|
|
return award != null ? Results.Ok(award) : Results.NotFound();
|
|
})
|
|
.RequireAuthorization()
|
|
.WithDescription("Get award by ID")
|
|
.WithName(typeof(GetAwardByIdEndpoint).ToEndpointName())
|
|
.MapToApiVersion(new ApiVersion(1))
|
|
.Produces<Domain.Entities.Award>(StatusCodes.Status200OK)
|
|
.Produces(StatusCodes.Status404NotFound)
|
|
.Produces(StatusCodes.Status401Unauthorized)
|
|
.WithTags(EndpointTags.Grants);
|
|
}
|
|
}
|