chore: update counts to allow unix timeframe

This commit is contained in:
Gabe Farrell 2025-12-29 16:02:55 -05:00
parent dfe3b5c90d
commit ef27dce5e3
6 changed files with 69 additions and 33 deletions

View file

@ -42,35 +42,35 @@ func StatsHandler(store db.DB) http.HandlerFunc {
l.Debug().Msgf("StatsHandler: Fetching statistics for period '%s'", period)
listens, err := store.CountListens(r.Context(), period)
listens, err := store.CountListens(r.Context(), db.Timeframe{Period: period})
if err != nil {
l.Err(err).Msg("StatsHandler: Failed to fetch listen count")
utils.WriteError(w, "failed to get listens: "+err.Error(), http.StatusInternalServerError)
return
}
tracks, err := store.CountTracks(r.Context(), period)
tracks, err := store.CountTracks(r.Context(), db.Timeframe{Period: period})
if err != nil {
l.Err(err).Msg("StatsHandler: Failed to fetch track count")
utils.WriteError(w, "failed to get tracks: "+err.Error(), http.StatusInternalServerError)
return
}
albums, err := store.CountAlbums(r.Context(), period)
albums, err := store.CountAlbums(r.Context(), db.Timeframe{Period: period})
if err != nil {
l.Err(err).Msg("StatsHandler: Failed to fetch album count")
utils.WriteError(w, "failed to get albums: "+err.Error(), http.StatusInternalServerError)
return
}
artists, err := store.CountArtists(r.Context(), period)
artists, err := store.CountArtists(r.Context(), db.Timeframe{Period: period})
if err != nil {
l.Err(err).Msg("StatsHandler: Failed to fetch artist count")
utils.WriteError(w, "failed to get artists: "+err.Error(), http.StatusInternalServerError)
return
}
timeListenedS, err := store.CountTimeListened(r.Context(), period)
timeListenedS, err := store.CountTimeListened(r.Context(), db.Timeframe{Period: period})
if err != nil {
l.Err(err).Msg("StatsHandler: Failed to fetch time listened")
utils.WriteError(w, "failed to get time listened: "+err.Error(), http.StatusInternalServerError)

View file

@ -326,13 +326,13 @@ func TestImportKoito(t *testing.T) {
_, err = store.GetTrack(ctx, db.GetTrackOpts{Title: "GIRI GIRI", ArtistIDs: []int32{artist.ID}})
require.NoError(t, err)
count, err := store.CountTracks(ctx, db.PeriodAllTime)
count, err := store.CountTracks(ctx, db.Timeframe{Period: db.PeriodAllTime})
require.NoError(t, err)
assert.EqualValues(t, 4, count)
count, err = store.CountAlbums(ctx, db.PeriodAllTime)
count, err = store.CountAlbums(ctx, db.Timeframe{Period: db.PeriodAllTime})
require.NoError(t, err)
assert.EqualValues(t, 3, count)
count, err = store.CountArtists(ctx, db.PeriodAllTime)
count, err = store.CountArtists(ctx, db.Timeframe{Period: db.PeriodAllTime})
require.NoError(t, err)
assert.EqualValues(t, 6, count)