mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 00:14:00 +00:00
feat(multiplayer): expose active ranked season
This commit is contained in:
@@ -8,7 +8,10 @@ import (
|
||||
"github.com/cosmic-clash/cosmic-clash/server/domain"
|
||||
)
|
||||
|
||||
const RankedProfileSelectSQL = `SELECT rating, deviation, volatility, ranked_games, updated_at
|
||||
const RankedProfileSelectSQL = `SELECT rating, deviation, volatility, ranked_games, updated_at,
|
||||
COALESCE((SELECT season_id FROM seasons
|
||||
WHERE playlist = 'ranked' AND starts_at <= CURRENT_TIMESTAMP AND ends_at > CURRENT_TIMESTAMP
|
||||
ORDER BY starts_at DESC, season_id DESC LIMIT 1), '')
|
||||
FROM ratings
|
||||
WHERE player_id = $1`
|
||||
|
||||
@@ -19,11 +22,10 @@ WHERE player_id = $1`
|
||||
// the same way the in-memory RankedProfiles map api.Service still falls
|
||||
// back to already did: (zero value, false, nil).
|
||||
//
|
||||
// LastSeasonID and SeasonHistory are deliberately left at their zero values.
|
||||
// The ratings table has no "current season" column, and reconstructing
|
||||
// season history means a second query against ranked_season_rollovers with
|
||||
// its own display semantics to settle -- a real, separate piece of work,
|
||||
// not bundled into this read path speculatively.
|
||||
// LastSeasonID and SeasonHistory remain zero-valued because they describe
|
||||
// rollover history, while CurrentSeasonID is derived from the active ranked
|
||||
// season row. Keeping those concepts separate prevents the profile endpoint
|
||||
// from making a current season look already rolled over to maintenance.
|
||||
type PostgresRankedProfiles struct{ DB *sql.DB }
|
||||
|
||||
func (p PostgresRankedProfiles) Get(ctx context.Context, playerID string) (domain.RankedProfile, bool, error) {
|
||||
@@ -32,7 +34,7 @@ func (p PostgresRankedProfiles) Get(ctx context.Context, playerID string) (domai
|
||||
}
|
||||
var profile domain.RankedProfile
|
||||
err := p.DB.QueryRowContext(ctx, RankedProfileSelectSQL, playerID).
|
||||
Scan(&profile.Value, &profile.RD, &profile.Volatility, &profile.RankedGames, &profile.LastRatedAt)
|
||||
Scan(&profile.Value, &profile.RD, &profile.Volatility, &profile.RankedGames, &profile.LastRatedAt, &profile.CurrentSeasonID)
|
||||
if err == sql.ErrNoRows {
|
||||
return domain.RankedProfile{}, false, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user