39 lines
1.7 KiB
C#
39 lines
1.7 KiB
C#
using PostFundManagement.Application.Abstractions.Services;
|
|
using PostFundManagement.Application.Extensions;
|
|
using PostFundManagement.Domain.Abstractions;
|
|
using PostFundManagement.Domain.Errors;
|
|
using PostFundManagement.Domain.Extensions;
|
|
using PostFundManagement.Domain.Models;
|
|
using PostFundManagement.Domain.Security;
|
|
using Problems = Microsoft.AspNetCore.Mvc.ProblemDetails;
|
|
|
|
namespace PostFundManagement.Api.Endpoints.Projects;
|
|
|
|
[ApiVersionTarget(1)]
|
|
public class GetProjectEndpoint : IEndpoint
|
|
{
|
|
public void Map(IEndpointRouteBuilder builder)
|
|
{
|
|
builder.MapGet("api/projects/{projectId}", async (string projectId, IProjectService service,
|
|
CancellationToken cancellationToken = default) =>
|
|
await service.GetProjectAsync(projectId, cancellationToken) switch
|
|
{
|
|
{ IsSuccess: true, Value: var project } => Results.Ok(project),
|
|
var r when r.HasError<IdDecodeError>() => Results.Forbid(),
|
|
var r when r.HasError<NotFoundError>() => Results.NotFound(),
|
|
var r => Results.InternalServerError(r.Errors.ToProblems())
|
|
})
|
|
.WithDescription("Get project by ID")
|
|
.RequireAuthorization(Constants.MainScope)
|
|
.WithName(typeof(GetProjectEndpoint).ToEndpointName())
|
|
.MapToApiVersion(new ApiVersion(1))
|
|
.Produces<Project[]>(StatusCodes.Status200OK)
|
|
.Produces(StatusCodes.Status404NotFound)
|
|
.Produces(StatusCodes.Status403Forbidden)
|
|
.Produces(StatusCodes.Status401Unauthorized)
|
|
.Produces<Problems>(StatusCodes.Status500InternalServerError)
|
|
.WithTags(EndpointTags.Projects)
|
|
.CacheOutput();
|
|
}
|
|
}
|