From 359b1049c5707bfeecdf73c91c78003911698296 Mon Sep 17 00:00:00 2001 From: Wannes Gennar Date: Fri, 15 Nov 2024 10:22:43 +0100 Subject: [PATCH 1/2] add routing for space station endpoints added in #120 --- .../Controllers/V1/SpaceStationController.cs | 35 +++++++++++++++++++ src/Helldivers-2-API/Program.cs | 3 ++ 2 files changed, 38 insertions(+) create mode 100644 src/Helldivers-2-API/Controllers/V1/SpaceStationController.cs diff --git a/src/Helldivers-2-API/Controllers/V1/SpaceStationController.cs b/src/Helldivers-2-API/Controllers/V1/SpaceStationController.cs new file mode 100644 index 0000000..7bf554a --- /dev/null +++ b/src/Helldivers-2-API/Controllers/V1/SpaceStationController.cs @@ -0,0 +1,35 @@ +using Helldivers.Core.Contracts.Collections; +using Helldivers.Models.V1; +using Microsoft.AspNetCore.Mvc; + +namespace Helldivers.API.Controllers.V1; + +/// +/// Contains API endpoints for . +/// +public static class SpaceStationController +{ + /// + /// Fetches a list of all available information available. + /// + [ProducesResponseType>(StatusCodes.Status200OK)] + public static async Task Index(HttpContext context, IStore store) + { + var stations = await store.AllAsync(context.RequestAborted); + + return Results.Ok(stations); + } + + /// + /// Fetches a specific identified by . + /// + public static async Task Show(HttpContext context, IStore store, [FromRoute] int index) + { + var station = await store.GetAsync(index, context.RequestAborted); + + if (station is null) + return Results.NotFound(); + + return Results.Ok(station); + } +} diff --git a/src/Helldivers-2-API/Program.cs b/src/Helldivers-2-API/Program.cs index c90ed9e..024f6cf 100644 --- a/src/Helldivers-2-API/Program.cs +++ b/src/Helldivers-2-API/Program.cs @@ -275,6 +275,9 @@ v1.MapGet("/planets/{index:int}", PlanetController.Show); v1.MapGet("/planet-events", PlanetController.WithEvents); +v1.MapGet("/space-stations", SpaceStationController.Index); +v1.MapGet("/space/stations/{index:int}", SpaceStationController.Show); + v1.MapGet("/steam", SteamController.Index); v1.MapGet("/steam/{gid}", SteamController.Show); From d09fc13e56ccf09c0ed505a8edfa1a5947a36e70 Mon Sep 17 00:00:00 2001 From: TheDarkGlobe Date: Fri, 15 Nov 2024 16:17:35 +0100 Subject: [PATCH 2/2] Fix whitespace formatting --- src/Helldivers-2-API/Controllers/V1/SpaceStationController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helldivers-2-API/Controllers/V1/SpaceStationController.cs b/src/Helldivers-2-API/Controllers/V1/SpaceStationController.cs index 7bf554a..4df3e07 100644 --- a/src/Helldivers-2-API/Controllers/V1/SpaceStationController.cs +++ b/src/Helldivers-2-API/Controllers/V1/SpaceStationController.cs @@ -16,7 +16,7 @@ public static class SpaceStationController public static async Task Index(HttpContext context, IStore store) { var stations = await store.AllAsync(context.RequestAborted); - + return Results.Ok(stations); }