Skip to content

Commit

Permalink
add routing for space station endpoints added in #120 (#124)
Browse files Browse the repository at this point in the history
* add routing for space station endpoints added in #120

* Fix whitespace formatting

---------

Co-authored-by: TheDarkGlobe <[email protected]>
  • Loading branch information
dealloc and lambstream authored Nov 15, 2024
1 parent 86336c2 commit 857d396
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Helldivers-2-API/Controllers/V1/SpaceStationController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Helldivers.Core.Contracts.Collections;
using Helldivers.Models.V1;
using Microsoft.AspNetCore.Mvc;

namespace Helldivers.API.Controllers.V1;

/// <summary>
/// Contains API endpoints for <see cref="SpaceStation" />.
/// </summary>
public static class SpaceStationController
{
/// <summary>
/// Fetches a list of all available <see cref="SpaceStation" /> information available.
/// </summary>
[ProducesResponseType<List<SpaceStation>>(StatusCodes.Status200OK)]
public static async Task<IResult> Index(HttpContext context, IStore<SpaceStation, int> store)
{
var stations = await store.AllAsync(context.RequestAborted);

return Results.Ok(stations);
}

/// <summary>
/// Fetches a specific <see cref="SpaceStation" /> identified by <paramref name="index" />.
/// </summary>
public static async Task<IResult> Show(HttpContext context, IStore<SpaceStation, int> store, [FromRoute] int index)
{
var station = await store.GetAsync(index, context.RequestAborted);

if (station is null)
return Results.NotFound();

return Results.Ok(station);
}
}
3 changes: 3 additions & 0 deletions src/Helldivers-2-API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 857d396

Please sign in to comment.