Refactor runtime bootstrap and ship control flows

This commit is contained in:
2026-04-03 01:12:26 -04:00
parent 0bb72bee35
commit 706e1cda8f
129 changed files with 9588 additions and 3548 deletions

View File

@@ -0,0 +1,25 @@
using FastEndpoints;
namespace SpaceGame.Api.Universe.Api;
public sealed class CreateFactionHandler(WorldService worldService) : Endpoint<CreateFactionCommandRequest, FactionSnapshot>
{
public override void Configure()
{
Post("/api/gm/factions");
Policies(AuthPolicyNames.GmAccess);
}
public override async Task HandleAsync(CreateFactionCommandRequest request, CancellationToken cancellationToken)
{
try
{
await SendOkAsync(worldService.CreateFaction(request.FactionId), cancellationToken);
}
catch (InvalidOperationException ex)
{
AddError(ex.Message);
await SendErrorsAsync(cancellation: cancellationToken);
}
}
}

View File

@@ -8,7 +8,7 @@ public sealed class GetBalanceHandler(IBalanceService balanceService) : Endpoint
public override void Configure()
{
Get("/api/balance");
AllowAnonymous();
Policies(AuthPolicyNames.GmAccess);
}
public override Task HandleAsync(CancellationToken cancellationToken) =>

View File

@@ -9,7 +9,7 @@ public sealed class GetTelemetryHandler(TelemetryService telemetry, WorldService
public override void Configure()
{
Get("/api/telemetry");
AllowAnonymous();
Policies(AuthPolicyNames.GmAccess);
}
public override Task HandleAsync(CancellationToken cancellationToken)

View File

@@ -0,0 +1,17 @@
using FastEndpoints;
namespace SpaceGame.Api.Universe.Api;
public sealed class GetVersionHandler(AppVersionService appVersionService) : EndpointWithoutRequest<VersionInfoSnapshot>
{
public override void Configure()
{
Get("/api/version");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken cancellationToken)
{
await SendOkAsync(appVersionService.GetSnapshot(), cancellationToken);
}
}

View File

@@ -7,7 +7,7 @@ public sealed class ResetWorldHandler(WorldService worldService) : EndpointWitho
public override void Configure()
{
Post("/api/world/reset");
AllowAnonymous();
Policies(AuthPolicyNames.GmAccess);
}
public override Task HandleAsync(CancellationToken cancellationToken) =>

View File

@@ -0,0 +1,25 @@
using FastEndpoints;
namespace SpaceGame.Api.Universe.Api;
public sealed class SpawnShipHandler(WorldService worldService) : Endpoint<SpawnShipCommandRequest, ShipSnapshot>
{
public override void Configure()
{
Post("/api/gm/ships");
Policies(AuthPolicyNames.GmAccess);
}
public override async Task HandleAsync(SpawnShipCommandRequest request, CancellationToken cancellationToken)
{
try
{
await SendOkAsync(worldService.SpawnShip(request), cancellationToken);
}
catch (InvalidOperationException ex)
{
AddError(ex.Message);
await SendErrorsAsync(cancellation: cancellationToken);
}
}
}

View File

@@ -0,0 +1,25 @@
using FastEndpoints;
namespace SpaceGame.Api.Universe.Api;
public sealed class SpawnStationHandler(WorldService worldService) : Endpoint<SpawnStationCommandRequest, StationSnapshot>
{
public override void Configure()
{
Post("/api/gm/stations");
Policies(AuthPolicyNames.GmAccess);
}
public override async Task HandleAsync(SpawnStationCommandRequest request, CancellationToken cancellationToken)
{
try
{
await SendOkAsync(worldService.SpawnStation(request), cancellationToken);
}
catch (InvalidOperationException ex)
{
AddError(ex.Message);
await SendErrorsAsync(cancellation: cancellationToken);
}
}
}

View File

@@ -8,7 +8,7 @@ public sealed class UpdateBalanceHandler(IBalanceService balanceService) : Endpo
public override void Configure()
{
Put("/api/balance");
AllowAnonymous();
Policies(AuthPolicyNames.GmAccess);
}
public override Task HandleAsync(BalanceOptions req, CancellationToken cancellationToken)