Return Array of KeyValuePairs instead of Dictionary (so it does not appear to be an object)
This commit is contained in:
parent
e11390f632
commit
227346e096
@ -10,16 +10,17 @@ public class TimeTrackController(Context databaseContext) : ApiController(typeof
|
|||||||
{
|
{
|
||||||
|
|
||||||
[HttpGet("{steamId}")]
|
[HttpGet("{steamId}")]
|
||||||
[ProducesResponseType<Dictionary<ulong, TrackedTime[]>>(Status200OK)]
|
[ProducesResponseType<KeyValuePair<ulong, TrackedTime[]>[]>(Status200OK)]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType(Status404NotFound)]
|
||||||
public IActionResult GetTrackedTime(ulong steamId)
|
public IActionResult GetTrackedTime(ulong steamId)
|
||||||
{
|
{
|
||||||
if (databaseContext.Players.Find(steamId) is not { } player)
|
if (databaseContext.Players.Find(steamId) is not { } player)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
databaseContext.Entry(player).Collection(p => p.TrackedTimes).Load();
|
databaseContext.Entry(player).Collection(p => p.TrackedTimes).Load();
|
||||||
Dictionary<ulong, TrackedTime[]> ret = player.TrackedTimes
|
KeyValuePair<ulong, TrackedTime[]>[] ret = player.TrackedTimes
|
||||||
.GroupBy(t => t.Game)
|
.GroupBy(t => t.Game)
|
||||||
.ToDictionary(t => t.Key.AppId, t => t.ToArray());
|
.Select(t => new KeyValuePair<ulong, TrackedTime[]>(t.Key.AppId, t.ToArray()))
|
||||||
|
.ToArray();
|
||||||
return Ok(ret);
|
return Ok(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,16 +55,17 @@ public class TimeTrackController(Context databaseContext) : ApiController(typeof
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{steamId}/Total/PerGame")]
|
[HttpGet("{steamId}/Total/PerGame")]
|
||||||
[ProducesResponseType<Dictionary<ulong, ulong>>(Status200OK)]
|
[ProducesResponseType<KeyValuePair<ulong, ulong>[]>(Status200OK)]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType(Status404NotFound)]
|
||||||
public IActionResult GetTrackedTimeAll(ulong steamId)
|
public IActionResult GetTrackedTimeAll(ulong steamId)
|
||||||
{
|
{
|
||||||
if (databaseContext.Players.Find(steamId) is not { } player)
|
if (databaseContext.Players.Find(steamId) is not { } player)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
databaseContext.Entry(player).Collection(p => p.TrackedTimes).Load();
|
databaseContext.Entry(player).Collection(p => p.TrackedTimes).Load();
|
||||||
Dictionary<ulong, ulong> trackedTimes = player.TrackedTimes
|
KeyValuePair<ulong, ulong>[] trackedTimes = player.TrackedTimes
|
||||||
.GroupBy(t => t.Game)
|
.GroupBy(t => t.Game)
|
||||||
.ToDictionary(t => t.Key.AppId, t => t.MaxBy(time => time.TimePlayed)?.TimePlayed??0);
|
.Select(t => new KeyValuePair<ulong, ulong>(t.Key.AppId, t.MaxBy(time => time.TimePlayed)?.TimePlayed ?? 0))
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
return Ok(trackedTimes);
|
return Ok(trackedTimes);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user