Compare commits

...

3 Commits

3 changed files with 26 additions and 6 deletions

View File

@ -10,16 +10,17 @@ public class TimeTrackController(Context databaseContext) : ApiController(typeof
{
[HttpGet("{steamId}")]
[ProducesResponseType<Dictionary<ulong, TrackedTime[]>>(Status200OK)]
[ProducesResponseType<KeyValuePair<ulong, TrackedTime[]>[]>(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<ulong, TrackedTime[]> ret = player.TrackedTimes
KeyValuePair<ulong, TrackedTime[]>[] ret = player.TrackedTimes
.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);
}
@ -53,17 +54,33 @@ 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<Dictionary<ulong, ulong>>(Status200OK)]
[ProducesResponseType<KeyValuePair<ulong, ulong>[]>(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<ulong, ulong> trackedTimes = player.TrackedTimes
KeyValuePair<ulong, ulong>[] trackedTimes = player.TrackedTimes
.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);
}

View File

@ -139,6 +139,8 @@ public class Tracker : IDisposable
{
Log.Debug($"Updating game times for player {player}");
GetRecentlyPlayedGames recentlyPlayed = Steam.GetRecentlyPlayedGames(player.SteamId);
if (recentlyPlayed.total_count < 1)
return;
foreach (SteamGame recentlyPlayedGame in recentlyPlayed.games)
{
string? iconUrlStr = recentlyPlayedGame.img_icon_url is not null

View File

@ -6,4 +6,5 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMigrationCommandExecutor_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fb43021565ba7f13262dd95827ae378ea6015db2c146979398f92c7356d98488_003FMigrationCommandExecutor_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ARelationalConnection_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F696ea149e41ddc60bdd9238370d01ba5f417a4a91ce8ac42c17d4eee0afa038_003FRelationalConnection_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASingleQueryingEnumerable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F413341ec7da6e42cb630e52ba9208edacb2e7267da1d9296f51628fcd35e81d9_003FSingleQueryingEnumerable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AStackFrameIterator_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fbf07be36dfaa4f47b843d44a6617c8b9d19e00_003Fa5_003F6dee0ce4_003FStackFrameIterator_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AXmlTextReaderImpl_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ff3fbda37b1e0423781e129b1ac69751d7a1a00_003F84_003F4c900766_003FXmlTextReaderImpl_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>