up
Some checks failed
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Mirror Thin Bundle Sign & Verify / mirror-sign (push) Has been cancelled
api-governance / spectral-lint (push) Has been cancelled
Some checks failed
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Mirror Thin Bundle Sign & Verify / mirror-sign (push) Has been cancelled
api-governance / spectral-lint (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using StellaOps.Policy.Engine.Ledger;
|
||||
|
||||
namespace StellaOps.Policy.Engine.Endpoints;
|
||||
|
||||
public static class LedgerExportEndpoint
|
||||
{
|
||||
public static IEndpointRouteBuilder MapLedgerExport(this IEndpointRouteBuilder routes)
|
||||
{
|
||||
routes.MapPost("/policy/ledger/export", BuildAsync)
|
||||
.WithName("PolicyEngine.Ledger.Export");
|
||||
|
||||
routes.MapGet("/policy/ledger/export/{exportId}", GetAsync)
|
||||
.WithName("PolicyEngine.Ledger.GetExport");
|
||||
|
||||
return routes;
|
||||
}
|
||||
|
||||
private static async Task<IResult> BuildAsync(
|
||||
[FromBody] LedgerExportRequest request,
|
||||
LedgerExportService service,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var export = await service.BuildAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
return Results.Json(export);
|
||||
}
|
||||
catch (Exception ex) when (ex is ArgumentException or KeyNotFoundException)
|
||||
{
|
||||
return Results.BadRequest(new { message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<IResult> GetAsync(
|
||||
[FromRoute] string exportId,
|
||||
LedgerExportService service,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var export = await service.GetAsync(exportId, cancellationToken).ConfigureAwait(false);
|
||||
return export is null ? Results.NotFound() : Results.Json(export);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user