Skip to content

Commit

Permalink
Let score board endpoint return a custom response to be tailored to t…
Browse files Browse the repository at this point in the history
…he usage
  • Loading branch information
J12934 committed Dec 11, 2024
1 parent 8612cdf commit a43f10a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 20 additions & 3 deletions balancer/routes/score-board.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ import (
)

type ScoreBoardResponse struct {
TotalTeams int `json:"totalTeams"`
TopTeams []*scoring.TeamScore `json:"teams"`
TotalTeams int `json:"totalTeams"`
TopTeams []*TeamScore `json:"teams"`
}

type TeamScore struct {
Name string `json:"name"`
Score int `json:"score"`
Position int `json:"position"`
SolvedChallengeCount int `json:"solvedChallengeCount"`
}

func handleScoreBoard(bundle *b.Bundle, scoringService *scoring.ScoringService) http.Handler {
Expand Down Expand Up @@ -47,9 +54,19 @@ func handleScoreBoard(bundle *b.Bundle, scoringService *scoring.ScoringService)
topTeams = totalTeams
}

convertedTopScores := make([]*TeamScore, len(topTeams))
for i, topTeam := range topTeams {
convertedTopScores[i] = &TeamScore{
Name: topTeam.Name,
Score: topTeam.Score,
Position: topTeam.Position,
SolvedChallengeCount: len(topTeam.Challenges),
}
}

response := ScoreBoardResponse{
TotalTeams: len(totalTeams),
TopTeams: topTeams,
TopTeams: convertedTopScores,
}

responseBytes, err := json.Marshal(response)
Expand Down
4 changes: 2 additions & 2 deletions balancer/ui/src/pages/ScoreOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface Team {
name: string;
score: number;
position: number;
challenges: string[];
solvedChallengeCount: number;
}

async function fetchTeams(lastSeen: Date | null): Promise<null | Team[]> {
Expand Down Expand Up @@ -117,7 +117,7 @@ export default function ScoreOverviewPage({
<td className="text-right text-s p-2 px-4">
{team.score} points
<p className="text-gray-500 m-1">
{team.challenges.length} solved challenges
{team.solvedChallengeCount} solved challenges
</p>
</td>
</tr>
Expand Down

0 comments on commit a43f10a

Please sign in to comment.