Skip to content

Commit

Permalink
feature: change payloads of raw
Browse files Browse the repository at this point in the history
Changes how the raw endpoints provide their data.
Rather than providing serialized versions of the endpoints we send the raw binary payloads

fix #41
  • Loading branch information
dealloc committed Apr 4, 2024
1 parent b4d3cc1 commit d2d687b
Show file tree
Hide file tree
Showing 16 changed files with 224 additions and 311 deletions.
39 changes: 19 additions & 20 deletions src/Helldivers-2-API/Controllers/ArrowHeadController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Helldivers.Core.Contracts;
using Helldivers.Core.Contracts.Collections;
using Helldivers.Core.Storage.ArrowHead;
using Helldivers.Models.ArrowHead;
using Microsoft.AspNetCore.Mvc;

Expand All @@ -14,66 +13,66 @@ public static class ArrowHeadController
/// Returns the currently active war season ID.
/// </summary>
[ProducesResponseType<WarId>(StatusCodes.Status200OK)]
public static async Task<IResult> WarId(HttpContext context, IStore<WarId> store)
public static async Task<IResult> WarId(HttpContext context, ArrowHeadStore store)
{
var result = await store.Get(context.RequestAborted);
var warId = await store.GetWarId(context.RequestAborted);

return Results.Ok(result);
return Results.Bytes(warId, contentType: "application/json");
}

/// <summary>
/// Get a snapshot of the current war status.
/// </summary>
[ProducesResponseType<WarStatus>(StatusCodes.Status200OK)]
public static async Task<IResult> Status(HttpContext context, IStore<WarStatus> store)
public static async Task<IResult> Status(HttpContext context, ArrowHeadStore store)
{
var status = await store.Get(context.RequestAborted);
var status = await store.GetWarStatus(context.RequestAborted);

return Results.Ok(status);
return Results.Bytes(status, contentType: "application/json");
}

/// <summary>
/// Gets the current war info.
/// </summary>
[ProducesResponseType<WarInfo>(StatusCodes.Status200OK)]
public static async Task<IResult> WarInfo(HttpContext context, IStore<WarInfo> store)
public static async Task<IResult> WarInfo(HttpContext context, ArrowHeadStore store)
{
var info = await store.Get(context.RequestAborted);
var info = await store.GetWarInfo(context.RequestAborted);

return Results.Ok(info);
return Results.Bytes(info, contentType: "application/json");
}

/// <summary>
/// Gets the current war info.
/// </summary>
[ProducesResponseType<WarSummary>(StatusCodes.Status200OK)]
public static async Task<IResult> Summary(HttpContext context, IStore<WarSummary> store)
public static async Task<IResult> Summary(HttpContext context, ArrowHeadStore store)
{
var summary = await store.Get(context.RequestAborted);
var summary = await store.GetWarSummary(context.RequestAborted);

return Results.Ok(summary);
return Results.Bytes(summary, contentType: "application/json");
}

/// <summary>
/// Retrieves a list of news messages from Super Earth.
/// </summary>
[ProducesResponseType<List<NewsFeedItem>>(StatusCodes.Status200OK)]
public static async Task<IResult> NewsFeed(HttpContext context, IStore<NewsFeedItem, int> store)
public static async Task<IResult> NewsFeed(HttpContext context, ArrowHeadStore store)
{
var items = await store.AllAsync(context.RequestAborted);
var items = await store.GetNewsFeeds(context.RequestAborted);

return Results.Ok(items);
return Results.Bytes(items, contentType: "application/json");
}

/// <summary>
/// Retrieves a list of currently active assignments (like Major Orders).
/// </summary>
[ProducesResponseType<List<Assignment>>(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status503ServiceUnavailable)]
public static async Task<IResult> Assignments(HttpContext context, IStore<Assignment, int> store)
public static async Task<IResult> Assignments(HttpContext context, ArrowHeadStore store)
{
var assignments = await store.AllAsync(context.RequestAborted);
var assignments = await store.GetAssignments(context.RequestAborted);

return Results.Ok(assignments);
return Results.Bytes(assignments, contentType: "application/json");
}
}
38 changes: 19 additions & 19 deletions src/Helldivers-2-API/wwwroot/Helldivers-2-API.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -46,7 +46,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -77,7 +77,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -108,7 +108,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -139,7 +139,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -173,7 +173,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -210,7 +210,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -241,7 +241,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -275,7 +275,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -318,7 +318,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -352,7 +352,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -395,7 +395,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -429,7 +429,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -472,7 +472,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -506,7 +506,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -549,7 +549,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -583,7 +583,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -618,7 +618,7 @@
},
{
"url": "/",
"description": "The dotnet helldivers server"
"description": "The development server"
}
],
"get": {
Expand Down Expand Up @@ -1801,4 +1801,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -869,4 +869,4 @@
}
}
}
}
}
15 changes: 1 addition & 14 deletions src/Helldivers-2-Core/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Helldivers.Core.Storage.ArrowHead;
using Helldivers.Core.Storage.Steam;
using Helldivers.Core.Storage.V1;
using Helldivers.Models.ArrowHead;
using Helldivers.Models.V1;
using Microsoft.Extensions.DependencyInjection;

Expand Down Expand Up @@ -35,20 +34,8 @@ public static IServiceCollection AddHelldivers(this IServiceCollection services)
/// </summary>
public static IServiceCollection AddArrowHeadStores(this IServiceCollection services)
{
// Register facade for all stores below
services.AddSingleton<ArrowHeadFacade>();

// Register all stores
services.AddSingleton<IStore<WarInfo>, WarInfoStore>();
services.AddSingleton<WarStatusStore>();
services.AddSingleton<IStore<WarStatus>>(provider => provider.GetRequiredService<WarStatusStore>());
services.AddSingleton<IStore<WarSummary>, WarSummaryStore>();
services.AddSingleton<Storage.ArrowHead.AssignmentStore>();
services.AddSingleton<IStore<Models.ArrowHead.Assignment, int>>(provider =>
provider.GetRequiredService<Storage.ArrowHead.AssignmentStore>());
services.AddSingleton<NewsFeedStore>();
services.AddSingleton<IStore<NewsFeedItem, int>>(provider => provider.GetRequiredService<NewsFeedStore>());
services.AddSingleton<IStore<WarId>, WarIdStore>();
services.AddSingleton<ArrowHeadStore>();

return services;
}
Expand Down
29 changes: 0 additions & 29 deletions src/Helldivers-2-Core/Facades/ArrowHeadFacade.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Helldivers-2-Core/Localization/CultureDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Helldivers.Core.Localization;
/// Specialized version of <see cref="Dictionary{TKey,TValue}" /> that intelligently maps <see cref="CultureInfo" /> as
/// keys (eg, if "en-UK" does not exist but "en-US" it'll match).
/// </summary>
public class CultureDictionary<T> where T : class
public class CultureDictionary<T>
{
private readonly Dictionary<CultureInfo, T> _items;

Expand Down
Loading

0 comments on commit d2d687b

Please sign in to comment.