Files
Website/BlazorApp/Endpoints/DeveloperEndpoints.cs
SysAdmin a4d2e571d5
All checks were successful
Build and Deploy / deploy (push) Successful in 17s
fix(developers): return 200 on partial provisioning failure
The approval endpoint now always returns 200 when provisioning was
attempted, with success/failure details in the response body. This
allows the SilverDESK webhook step to proceed with remaining actions
(note, reply, status change) even when individual services fail.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 01:43:49 +00:00

50 lines
2.0 KiB
C#

using SilverLabs.Website.Models;
using SilverLabs.Website.Services;
namespace SilverLabs.Website.Endpoints;
public static class DeveloperEndpoints
{
public static void MapDeveloperEndpoints(this WebApplication app)
{
var group = app.MapGroup("/api/developers");
group.MapPost("/apply", async (DeveloperApplication application, DeveloperApplicationService service) =>
{
var (success, message) = await service.SubmitApplicationAsync(application);
return success
? Results.Ok(new { message })
: Results.Problem(message, statusCode: 502);
});
group.MapPost("/approve/{ticketId}", async (
string ticketId,
DeveloperTicketParsingService ticketService,
ProvisioningService provisioningService,
HttpContext context,
IConfiguration config) =>
{
var apiKey = context.Request.Headers["X-Api-Key"].FirstOrDefault();
var expectedKey = config["AdminApiKey"];
if (string.IsNullOrEmpty(expectedKey) || apiKey != expectedKey)
return Results.Unauthorized();
var ticket = await ticketService.FetchTicketAsync(ticketId);
if (ticket is null)
return Results.Problem("Failed to fetch ticket from SilverDESK", statusCode: 502);
var description = ticket.Value.GetProperty("description").GetString() ?? "";
var (fullName, email, desiredUsername) = ticketService.ParseApplicationFromDescription(description);
if (string.IsNullOrEmpty(fullName) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(desiredUsername))
return Results.Problem("Could not parse applicant details from ticket description", statusCode: 422);
var (success, message) = await provisioningService.ApproveApplicationAsync(
ticketId, desiredUsername, email, fullName);
return Results.Ok(new { success, message });
});
}
}