Skip to content

Commit

Permalink
Return correct tournament details in console API leaderboard details …
Browse files Browse the repository at this point in the history
…endpoint. (#1295)
  • Loading branch information
zyro authored Jan 6, 2025
1 parent 8a72e2c commit 723250f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
## [Unreleased]
### Fixed
- Ensure persisted chat messages listing returns correct order.
- Return correct tournament details in console API leaderboard details endpoint.

## [3.25.0] - 2024-11-25
### Added
Expand Down
6 changes: 3 additions & 3 deletions server/console_leaderboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ func (s *ConsoleServer) GetLeaderboard(ctx context.Context, in *console.Leaderbo
var t *api.Tournament
var prevReset, nextReset int64
if l.IsTournament() {
results, err := TournamentList(ctx, s.logger, s.db, s.leaderboardCache, l.Category, l.Category, int(l.StartTime), int(l.EndTime), 1, nil)
results, err := TournamentsGet(ctx, s.logger, s.db, s.leaderboardCache, []string{in.Id})
if err != nil {
s.logger.Error("Error retrieving tournament.", zap.Error(err))
return nil, status.Error(codes.Internal, "Error retrieving tournament.")
}

if len(results.Tournaments) == 0 {
if len(results) == 0 {
return nil, status.Error(codes.NotFound, "Leaderboard not found.")
}

t = results.Tournaments[0]
t = results[0]
}

if l.ResetSchedule != nil {
Expand Down
6 changes: 3 additions & 3 deletions server/core_tournament.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ ON CONFLICT(owner_id, leaderboard_id, expiry_time) DO NOTHING`

return nil
}); err != nil {
if err == runtime.ErrTournamentMaxSizeReached {
if errors.Is(err, runtime.ErrTournamentMaxSizeReached) {
logger.Info("Failed to join tournament, reached max size allowed.", zap.String("tournament_id", tournamentId), zap.String("owner", ownerID.String()), zap.String("username", username))
return err
}
Expand Down Expand Up @@ -266,7 +266,7 @@ WHERE id = ANY($1::text[])`
for rows.Next() {
tournament, err := parseTournament(rows, now)
if err != nil {
if err == runtime.ErrTournamentNotFound {
if errors.Is(err, runtime.ErrTournamentNotFound) {
// This ID mapped to a non-tournament leaderboard, just skip it.
continue
}
Expand Down Expand Up @@ -515,7 +515,7 @@ func TournamentRecordWrite(ctx context.Context, logger *zap.Logger, db *sql.DB,
var exists int
err := db.QueryRowContext(ctx, "SELECT 1 FROM leaderboard_record WHERE leaderboard_id = $1 AND owner_id = $2 AND expiry_time = $3", leaderboard.Id, ownerId, expiryTime).Scan(&exists)
if err != nil {
if err == sql.ErrNoRows {
if errors.Is(err, sql.ErrNoRows) {
// Tournament required join but no row was found to update.
return nil, runtime.ErrTournamentWriteJoinRequired
}
Expand Down

0 comments on commit 723250f

Please sign in to comment.