Refactored endpoints to be more functional and more expressive
This commit is contained in:
@@ -4,6 +4,7 @@ using PostFundManagement.Domain;
|
||||
using PostFundManagement.Domain.Abstractions;
|
||||
using PostFundManagement.Domain.Extensions;
|
||||
using PostFundManagement.Domain.Security;
|
||||
using Problems = Microsoft.AspNetCore.Mvc.ProblemDetails;
|
||||
|
||||
namespace PostFundManagement.Api.Endpoints.Evidence;
|
||||
|
||||
@@ -14,20 +15,18 @@ public class GetEvidenceFilesEndpoint : IEndpoint
|
||||
{
|
||||
builder.MapGet("api/evidence/files/{page:int}/{pageSize:int}", async (EvidenceService service,
|
||||
int page = 1, int pageSize = 100, CancellationToken cancellationToken = default) =>
|
||||
{
|
||||
var result = await service.GetEvidenceFilesAsync(Pagination.Create(page, pageSize), cancellationToken);
|
||||
|
||||
return result.IsSuccess
|
||||
? Results.Ok(result.Value)
|
||||
: Results.BadRequest(result.Errors.ToProblems());
|
||||
})
|
||||
.WithDescription("Get a list of all uploaded evidence files metadata")
|
||||
.WithName(typeof(GetEvidenceFilesEndpoint).ToEndpointName())
|
||||
.MapToApiVersion(new ApiVersion(1))
|
||||
.Produces<Domain.Models.Evidence[]>(StatusCodes.Status200OK)
|
||||
.Produces<Microsoft.AspNetCore.Mvc.ProblemDetails>(StatusCodes.Status400BadRequest)
|
||||
.Produces(StatusCodes.Status401Unauthorized)
|
||||
.WithTags(EndpointTags.Evidence)
|
||||
.CacheOutput();
|
||||
await service.GetEvidenceFilesAsync(Pagination.Create(page, pageSize), cancellationToken) switch
|
||||
{
|
||||
{ IsSuccess: true, Value: var evidences} => Results.Ok(evidences),
|
||||
var r => Results.InternalServerError(r.Errors.ToProblems())
|
||||
})
|
||||
.WithDescription("Get a list of all uploaded evidence files metadata")
|
||||
.WithName(typeof(GetEvidenceFilesEndpoint).ToEndpointName())
|
||||
.MapToApiVersion(new ApiVersion(1))
|
||||
.Produces<Domain.Models.Evidence[]>(StatusCodes.Status200OK)
|
||||
.Produces<Problems>(StatusCodes.Status500InternalServerError)
|
||||
.Produces(StatusCodes.Status401Unauthorized)
|
||||
.WithTags(EndpointTags.Evidence)
|
||||
.CacheOutput();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user