33 lines
1.4 KiB
C#
33 lines
1.4 KiB
C#
using PostFundManagement.Application.Abstractions.Services;
|
|
using PostFundManagement.Application.Extensions;
|
|
using PostFundManagement.Domain;
|
|
using PostFundManagement.Domain.Abstractions;
|
|
using PostFundManagement.Domain.Extensions;
|
|
using PostFundManagement.Domain.Models;
|
|
|
|
namespace PostFundManagement.Api.Endpoints.Projects;
|
|
|
|
[ApiVersionTarget(1)]
|
|
public class GetProjectsEndpoint : IEndpoint
|
|
{
|
|
public void Map(IEndpointRouteBuilder builder)
|
|
{
|
|
builder.MapGet("api/projects", async (IProjectService service,
|
|
int page = 1, int pageSize = 100, CancellationToken cancellationToken = default) =>
|
|
await service.GetProjectsAsync(Pagination.Create(page, pageSize), cancellationToken) switch
|
|
{
|
|
{ IsSuccess: true, Value: var projects } => Results.Ok(projects),
|
|
var r => Results.InternalServerError(r.Errors.ToProblems())
|
|
})
|
|
.WithDescription("Get a list of projects")
|
|
.RequireAuthorization(Constants.MainScope)
|
|
.WithName(typeof(GetProjectsEndpoint).ToEndpointName())
|
|
.MapToApiVersion(new ApiVersion(1))
|
|
.Produces<Project[]>(StatusCodes.Status200OK)
|
|
.Produces<Problems>(StatusCodes.Status500InternalServerError)
|
|
.Produces(StatusCodes.Status401Unauthorized)
|
|
.WithTags(EndpointTags.Projects)
|
|
.CacheOutput();
|
|
}
|
|
}
|