Add developer application page with form submission that creates tickets in SilverDESK. Includes provisioning service scaffolding for Mattermost, Mailcow, and Gitea account creation. Fixes API key header casing (X-API-Key) and ticket payload to match SilverDESK's CreateTicketDto contract. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
44 lines
1.5 KiB
C#
44 lines
1.5 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:int}", async (
|
|
int ticketId,
|
|
ApproveRequest request,
|
|
ProvisioningService service,
|
|
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 (success, message) = await service.ApproveApplicationAsync(
|
|
ticketId, request.Username, request.Email, request.FullName);
|
|
|
|
return success
|
|
? Results.Ok(new { message })
|
|
: Results.Problem(message, statusCode: 502);
|
|
});
|
|
}
|
|
}
|
|
|
|
public record ApproveRequest(string Username, string Email, string FullName);
|