using Microsoft.AspNetCore.Mvc; using StellaOps.Policy.Engine.Orchestration; namespace StellaOps.Policy.Engine.Endpoints; public static class OrchestratorJobEndpoint { public static IEndpointRouteBuilder MapOrchestratorJobs(this IEndpointRouteBuilder routes) { routes.MapPost("/policy/orchestrator/jobs", SubmitAsync) .WithName("PolicyEngine.Orchestrator.Jobs.Submit"); routes.MapPost("/policy/orchestrator/jobs/preview", PreviewAsync) .WithName("PolicyEngine.Orchestrator.Jobs.Preview"); routes.MapGet("/policy/orchestrator/jobs/{jobId}", GetAsync) .WithName("PolicyEngine.Orchestrator.Jobs.Get"); return routes; } private static async Task SubmitAsync( [FromBody] OrchestratorJobRequest request, OrchestratorJobService service, CancellationToken cancellationToken) { try { var job = await service.SubmitAsync(request, cancellationToken).ConfigureAwait(false); return Results.Json(job); } catch (ArgumentException ex) { return Results.BadRequest(new { message = ex.Message }); } } private static async Task PreviewAsync( [FromBody] OrchestratorJobRequest request, OrchestratorJobService service, CancellationToken cancellationToken) { try { var job = await service.PreviewAsync(request, cancellationToken).ConfigureAwait(false); return Results.Json(job); } catch (ArgumentException ex) { return Results.BadRequest(new { message = ex.Message }); } } private static async Task GetAsync( [FromRoute] string jobId, OrchestratorJobService service, CancellationToken cancellationToken) { var job = await service.GetAsync(jobId, cancellationToken).ConfigureAwait(false); return job is null ? Results.NotFound() : Results.Json(job); } }