Skip to content

Commit 4860ffa

Browse files
committed
move space station to V2
1 parent 4aacef7 commit 4860ffa

12 files changed

Lines changed: 40 additions & 33 deletions

File tree

src/Helldivers-2-API/Controllers/V1/SpaceStationController.cs renamed to src/Helldivers-2-API/Controllers/V2/SpaceStationController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using Helldivers.Core.Contracts.Collections;
2-
using Helldivers.Models.V1;
2+
using Helldivers.Models.V2;
33
using Microsoft.AspNetCore.Mvc;
44

5-
namespace Helldivers.API.Controllers.V1;
5+
namespace Helldivers.API.Controllers.V2;
66

77
/// <summary>
88
/// Contains API endpoints for <see cref="SpaceStation" />.

src/Helldivers-2-API/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,6 @@
281281
v1.MapGet("/planets/{index:int}", Helldivers.API.Controllers.V1.PlanetController.Show);
282282
v1.MapGet("/planet-events", Helldivers.API.Controllers.V1.PlanetController.WithEvents);
283283

284-
v1.MapGet("/space-stations", Helldivers.API.Controllers.V1.SpaceStationController.Index);
285-
v1.MapGet("/space-stations/{index:long}", Helldivers.API.Controllers.V1.SpaceStationController.Show);
286-
287284
v1.MapGet("/steam", Helldivers.API.Controllers.V1.SteamController.Index);
288285
v1.MapGet("/steam/{gid}", Helldivers.API.Controllers.V1.SteamController.Show);
289286

@@ -299,6 +296,9 @@
299296
v2.MapGet("/dispatches", Helldivers.API.Controllers.V2.DispatchController.Index);
300297
v2.MapGet("/dispatches/{index:int}", Helldivers.API.Controllers.V2.DispatchController.Show);
301298

299+
v2.MapGet("/space-stations", Helldivers.API.Controllers.V2.SpaceStationController.Index);
300+
v2.MapGet("/space-stations/{index:long}", Helldivers.API.Controllers.V2.SpaceStationController.Show);
301+
302302
#endregion
303303

304304
app.MapGet("/", () => @"Check out the documentation over at https://helldivers-2.github.io/api/

src/Helldivers-2-Core/Extensions/ServiceCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public static IServiceCollection AddV1Stores(this IServiceCollection services)
7474
services.AddSingleton<IStore<Campaign, int>, CampaignStore>();
7575
services.AddSingleton<IStore<Models.V1.Assignment, long>, Storage.V1.AssignmentStore>();
7676
services.AddSingleton<IStore<Dispatch, int>, DispatchStore>();
77-
services.AddSingleton<IStore<SpaceStation, long>, SpaceStationStore>();
7877

7978
// Register mappers
8079
services.AddSingleton<AssignmentMapper>();
@@ -83,7 +82,6 @@ public static IServiceCollection AddV1Stores(this IServiceCollection services)
8382
services.AddSingleton<PlanetMapper>();
8483
services.AddSingleton<StatisticsMapper>();
8584
services.AddSingleton<WarMapper>();
86-
services.AddSingleton<SpaceStationMapper>();
8785

8886
return services;
8987
}
@@ -97,9 +95,11 @@ public static IServiceCollection AddV2Stores(this IServiceCollection services)
9795
services.AddSingleton<V2Facade>();
9896

9997
services.AddSingleton<IStore<Models.V2.Dispatch, int>, Storage.V2.DispatchStore>();
98+
services.AddSingleton<IStore<Models.V2.SpaceStation, long>, Storage.V2.SpaceStationStore>();
10099

101100
// Register mappers
102101
services.AddSingleton<Mapping.V2.DispatchMapper>();
102+
services.AddSingleton<Mapping.V2.SpaceStationMapper>();
103103

104104
return services;
105105
}

src/Helldivers-2-Core/Facades/V1Facade.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ public sealed class V1Facade(
1919
IStore<Assignment, long> assignmentStore,
2020
AssignmentMapper assignmentMapper,
2121
IStore<Dispatch, int> dispatchStore,
22-
DispatchMapper dispatchMapper,
23-
IStore<SpaceStation, long> spaceStationStore,
24-
SpaceStationMapper spaceStationMapper
22+
DispatchMapper dispatchMapper
2523
)
2624
{
2725
/// <see cref="IStore{T,TKey}.SetStore" />
@@ -37,7 +35,6 @@ public async ValueTask UpdateStores(MappingContext context)
3735
await UpdateCampaignStore(context, planets);
3836
await UpdateAssignmentsStore(context);
3937
await UpdateDispatchStore(context);
40-
await UpdateSpaceStationStore(context, planets);
4138
}
4239

4340
private async ValueTask UpdateWarStore(MappingContext context, List<Planet> planets)
@@ -79,13 +76,4 @@ private async ValueTask UpdateDispatchStore(MappingContext context)
7976

8077
await dispatchStore.SetStore(dispatches);
8178
}
82-
83-
private async ValueTask UpdateSpaceStationStore(MappingContext context, List<Planet> planets)
84-
{
85-
var spaceStations = spaceStationMapper
86-
.MapToV1(context, planets)
87-
.ToList();
88-
89-
await spaceStationStore.SetStore(spaceStations);
90-
}
9179
}

src/Helldivers-2-Core/Facades/V2Facade.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using Helldivers.Core.Contracts.Collections;
22
using Helldivers.Core.Mapping;
33
using Helldivers.Core.Mapping.V2;
4+
using Helldivers.Models.V1;
45
using Helldivers.Models.V2;
6+
using Dispatch = Helldivers.Models.V2.Dispatch;
57

68
namespace Helldivers.Core.Facades;
79

@@ -10,13 +12,20 @@ namespace Helldivers.Core.Facades;
1012
/// </summary>
1113
public sealed class V2Facade(
1214
IStore<Dispatch, int> dispatchStore,
13-
DispatchMapper dispatchMapper
15+
DispatchMapper dispatchMapper,
16+
IStore<Planet, int> planetStore,
17+
IStore<SpaceStation, long> spaceStationStore,
18+
SpaceStationMapper spaceStationMapper
1419
)
1520
{
1621
/// <see cref="IStore{T,TKey}.SetStore" />
1722
public async ValueTask UpdateStores(MappingContext context)
1823
{
1924
await UpdateDispatchStore(context);
25+
26+
// Some mappers need access to the list of planets, so we fetch it from the freshly-mapped store.
27+
var planets = await planetStore.AllAsync();
28+
await UpdateSpaceStationStore(context, planets);
2029
}
2130

2231
private async ValueTask UpdateDispatchStore(MappingContext context)
@@ -28,4 +37,13 @@ private async ValueTask UpdateDispatchStore(MappingContext context)
2837

2938
await dispatchStore.SetStore(dispatches);
3039
}
40+
41+
private async ValueTask UpdateSpaceStationStore(MappingContext context, List<Planet> planets)
42+
{
43+
var spaceStations = spaceStationMapper
44+
.MapToV2(context, planets)
45+
.ToList();
46+
47+
await spaceStationStore.SetStore(spaceStations);
48+
}
3149
}

src/Helldivers-2-Core/Mapping/V1/SpaceStationMapper.cs renamed to src/Helldivers-2-Core/Mapping/V2/SpaceStationMapper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using Helldivers.Models;
21
using Helldivers.Models.V1;
3-
using Helldivers.Models.V1.SpaceStations;
2+
using Helldivers.Models.V2;
3+
using Helldivers.Models.V2.SpaceStations;
44

5-
namespace Helldivers.Core.Mapping.V1;
5+
namespace Helldivers.Core.Mapping.V2;
66

77
/// <summary>
88
/// Handles mapping for <see cref="SpaceStation" />.
@@ -15,7 +15,7 @@ public sealed class SpaceStationMapper
1515
/// <param name="context">The mapping context containing the invariant war status and other relevant data.</param>
1616
/// <param name="planets">The list of planets to map with.</param>
1717
/// <returns>An enumerable list of space stations mapped to the V1 model.</returns>
18-
public IEnumerable<SpaceStation> MapToV1(MappingContext context, List<Planet> planets)
18+
public IEnumerable<SpaceStation> MapToV2(MappingContext context, List<Planet> planets)
1919
{
2020
// Get a list of all assignments across all translations.
2121
var invariants = context.SpaceStations

src/Helldivers-2-Core/Storage/V1/SpaceStationStore.cs renamed to src/Helldivers-2-Core/Storage/V2/SpaceStationStore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Helldivers.Core.Contracts.Collections;
2-
using Helldivers.Models.V1;
2+
using Helldivers.Models.V2;
33

4-
namespace Helldivers.Core.Storage.V1;
4+
namespace Helldivers.Core.Storage.V2;
55

66
/// <inheritdoc cref="IStore{T,TKey}" />
77
public sealed class SpaceStationStore : StoreBase<SpaceStation, long>

src/Helldivers-2-Models/V1SerializerContext.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ namespace Helldivers.Models;
1818
[JsonSerializable(typeof(SteamNews))]
1919
[JsonSerializable(typeof(List<SteamNews>))]
2020
[JsonSerializable(typeof(War))]
21-
[JsonSerializable(typeof(SpaceStation))]
22-
[JsonSerializable(typeof(List<SpaceStation>))]
2321
[JsonSourceGenerationOptions(PropertyNameCaseInsensitive = true, UseStringEnumConverter = true)]
2422
public sealed partial class V1SerializerContext : JsonSerializerContext
2523
{

src/Helldivers-2-Models/V1/SpaceStation.cs renamed to src/Helldivers-2-Models/V2/SpaceStation.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using Helldivers.Models.V1.SpaceStations;
1+
using Helldivers.Models.V1;
2+
using Helldivers.Models.V2.SpaceStations;
23

3-
namespace Helldivers.Models.V1;
4+
namespace Helldivers.Models.V2;
45

56
/// <summary>
67
/// Represents a Super Earth Democracy Space Station.

src/Helldivers-2-Models/V1/SpaceStations/Cost.cs renamed to src/Helldivers-2-Models/V2/SpaceStations/Cost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Helldivers.Models.V1.SpaceStations;
1+
namespace Helldivers.Models.V2.SpaceStations;
22

33
public sealed record Cost(
44
string Id,

0 commit comments

Comments
 (0)