From 227346e096afae2a36c6ab93eb0b1141629997ea Mon Sep 17 00:00:00 2001 From: glax Date: Mon, 26 May 2025 19:07:48 +0200 Subject: [PATCH] Return Array of KeyValuePairs instead of Dictionary (so it does not appear to be an object) --- API/Controllers/TimeTrackController.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/API/Controllers/TimeTrackController.cs b/API/Controllers/TimeTrackController.cs index 2677a45..3d04f7a 100644 --- a/API/Controllers/TimeTrackController.cs +++ b/API/Controllers/TimeTrackController.cs @@ -10,16 +10,17 @@ public class TimeTrackController(Context databaseContext) : ApiController(typeof { [HttpGet("{steamId}")] - [ProducesResponseType>(Status200OK)] + [ProducesResponseType[]>(Status200OK)] [ProducesResponseType(Status404NotFound)] public IActionResult GetTrackedTime(ulong steamId) { if (databaseContext.Players.Find(steamId) is not { } player) return NotFound(); databaseContext.Entry(player).Collection(p => p.TrackedTimes).Load(); - Dictionary ret = player.TrackedTimes + KeyValuePair[] ret = player.TrackedTimes .GroupBy(t => t.Game) - .ToDictionary(t => t.Key.AppId, t => t.ToArray()); + .Select(t => new KeyValuePair(t.Key.AppId, t.ToArray())) + .ToArray(); return Ok(ret); } @@ -54,16 +55,17 @@ public class TimeTrackController(Context databaseContext) : ApiController(typeof } [HttpGet("{steamId}/Total/PerGame")] - [ProducesResponseType>(Status200OK)] + [ProducesResponseType[]>(Status200OK)] [ProducesResponseType(Status404NotFound)] public IActionResult GetTrackedTimeAll(ulong steamId) { if (databaseContext.Players.Find(steamId) is not { } player) return NotFound(); databaseContext.Entry(player).Collection(p => p.TrackedTimes).Load(); - Dictionary trackedTimes = player.TrackedTimes + KeyValuePair[] trackedTimes = player.TrackedTimes .GroupBy(t => t.Game) - .ToDictionary(t => t.Key.AppId, t => t.MaxBy(time => time.TimePlayed)?.TimePlayed??0); + .Select(t => new KeyValuePair(t.Key.AppId, t.MaxBy(time => time.TimePlayed)?.TimePlayed ?? 0)) + .ToArray(); return Ok(trackedTimes); }