using FastEndpoints; namespace SpaceGame.Api.PlayerFaction.Api; public sealed class UpsertPlayerDirectiveHandler(WorldService worldService) : Endpoint { public override void Configure() { Post("/api/player-faction/directives"); Put("/api/player-faction/directives/{directiveId}"); AllowAnonymous(); } public override async Task HandleAsync(PlayerDirectiveCommandRequest request, CancellationToken cancellationToken) { var directiveId = Route("directiveId"); var snapshot = worldService.UpsertPlayerDirective(string.IsNullOrWhiteSpace(directiveId) ? null : directiveId, request); if (snapshot is null) { await SendNotFoundAsync(cancellationToken); return; } await SendOkAsync(snapshot, cancellationToken); } }