Add Endpoint GET {steamId}/Total/{appId}"

This commit is contained in:
glax 2025-05-27 01:19:08 +02:00
parent 227346e096
commit 92397eea18

View File

@ -54,6 +54,21 @@ public class TimeTrackController(Context databaseContext) : ApiController(typeof
return Ok(sum);
}
[HttpGet("{steamId}/Total/{appId}")]
[ProducesResponseType<ulong>(Status200OK)]
[ProducesResponseType(Status404NotFound)]
public IActionResult GetTrackedTimeAll(ulong steamId, ulong appId)
{
if (databaseContext.Players.Find(steamId) is not { } player)
return NotFound();
if (databaseContext.Games.Find(appId) is not { } game)
return NotFound();
databaseContext.Entry(player).Collection(p => p.TrackedTimes).Load();
ulong? maxTime = player.TrackedTimes.Where(t => t.Game == game).MaxBy(t => t.TimePlayed)?.TimePlayed;
return maxTime is not null ? Ok(maxTime) : NoContent();
}
[HttpGet("{steamId}/Total/PerGame")]
[ProducesResponseType<KeyValuePair<ulong, ulong>[]>(Status200OK)]
[ProducesResponseType(Status404NotFound)]