aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/api/generated.go53
-rw-r--r--backend/api/handler.go15
-rw-r--r--backend/db/query.sql.go59
-rw-r--r--backend/query.sql5
4 files changed, 59 insertions, 73 deletions
diff --git a/backend/api/generated.go b/backend/api/generated.go
index a297c97..0616d51 100644
--- a/backend/api/generated.go
+++ b/backend/api/generated.go
@@ -79,8 +79,9 @@ type Problem struct {
// RankingEntry defines model for RankingEntry.
type RankingEntry struct {
- Player User `json:"player"`
- Score int `json:"score"`
+ Player User `json:"player"`
+ Score int `json:"score"`
+ SubmittedAt int64 `json:"submitted_at"`
}
// User defines model for User.
@@ -1127,30 +1128,30 @@ func (sh *strictHandler) PostLogin(ctx echo.Context) error {
// Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{
- "H4sIAAAAAAAC/+xYXW/bNhf+KwTfF+iNGttNEHTZVbq1RYeiMNoVw1AUAi0d20wpUiWpOl6h/z4cUl+U",
- "5FpJm24plovAInm+Hz485GeaqCxXEqQ19OIzzZlmGVjQ7msLLAUds8JuleZ/McuVxHEu6UU1SSMqWQb0",
- "gl4GqyKq4WPBNaT0wuoCImqSLWQMxe0+RwFjNZcbWpYRzZndxhuWQczTxgAOturr2QmKubSwAU1LVK3B",
- "5EoacAE9Yelr+FiAsfiVKGlBup8szwVPnOuzK+OjbPX+X8OaXtD/zdpkzfysmT3VWlWmUjCJ5rnPEtoi",
- "ujJWRvSZ0iuepiDv3nJrqozoK2WfqUKmd2/2lbJk7UyVEX0ra9TAdzAdWMPpSgIVeiHEtlY5aMs9FDIw",
- "hm0Af8I1y3KByHkhPzHB27pFI1ht4feuUfK+WahWV5C4gj+9hqRA/95YZgtnE2SRoZhUEhDIhZSoNaKm",
- "SBIwhkZ0p5XcxEyandtblmegCusX40cMLpzIgVxLJqqB91EnjFZdz/2IPne7qZ+MlJtcsH0sq9lWFa4n",
- "izFNaaFdDWMDiZK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",
+ "9zrt28WjM3zkLugrLnh4c46uTX/FBnrLqLX4AIP73WvzN+v9PxmKUzIFrd7GbhAIXBtXb725e7B6q0Ai",
+ "B5yqqqq/AwAA///orTnDMh4AAA==",
}
// GetSwagger returns the content of the embedded swagger specification file
diff --git a/backend/api/handler.go b/backend/api/handler.go
index 4514a25..2cb04c5 100644
--- a/backend/api/handler.go
+++ b/backend/api/handler.go
@@ -252,14 +252,15 @@ func (h *Handler) GetGameWatchRanking(ctx context.Context, request GetGameWatchR
for i, row := range rows {
ranking[i] = RankingEntry{
Player: User{
- UserID: int(row.UserID),
- Username: row.Username,
- DisplayName: row.DisplayName,
- IconPath: row.IconPath,
- IsAdmin: row.IsAdmin,
- Label: toNullable(row.Label),
+ UserID: int(row.User.UserID),
+ Username: row.User.Username,
+ DisplayName: row.User.DisplayName,
+ IconPath: row.User.IconPath,
+ IsAdmin: row.User.IsAdmin,
+ Label: toNullable(row.User.Label),
},
- Score: int(row.CodeSize),
+ Score: int(row.Submission.CodeSize),
+ SubmittedAt: row.Submission.CreatedAt.Time.Unix(),
}
}
return GetGameWatchRanking200JSONResponse{
diff --git a/backend/db/query.sql.go b/backend/db/query.sql.go
index c7f4fe9..5e840fa 100644
--- a/backend/db/query.sql.go
+++ b/backend/db/query.sql.go
@@ -274,7 +274,10 @@ func (q *Queries) GetLatestStatesOfMainPlayers(ctx context.Context, gameID int32
}
const getRanking = `-- name: GetRanking :many
-SELECT game_states.game_id, game_states.user_id, game_states.code, game_states.status, best_score_submission_id, users.user_id, username, display_name, icon_path, is_admin, label, users.created_at, submission_id, submissions.game_id, submissions.user_id, submissions.code, code_size, submissions.status, submissions.created_at FROM game_states
+SELECT
+ submissions.submission_id, submissions.game_id, submissions.user_id, submissions.code, submissions.code_size, submissions.status, submissions.created_at,
+ users.user_id, users.username, users.display_name, users.icon_path, users.is_admin, users.label, users.created_at
+FROM game_states
JOIN users ON game_states.user_id = users.user_id
JOIN submissions ON game_states.best_score_submission_id = submissions.submission_id
WHERE game_states.game_id = $1
@@ -282,25 +285,8 @@ ORDER BY submissions.code_size ASC, submissions.created_at ASC
`
type GetRankingRow struct {
- GameID int32
- UserID int32
- Code string
- Status string
- BestScoreSubmissionID *int32
- UserID_2 int32
- Username string
- DisplayName string
- IconPath *string
- IsAdmin bool
- Label *string
- CreatedAt pgtype.Timestamp
- SubmissionID int32
- GameID_2 int32
- UserID_3 int32
- Code_2 string
- CodeSize int32
- Status_2 string
- CreatedAt_2 pgtype.Timestamp
+ Submission Submission
+ User User
}
func (q *Queries) GetRanking(ctx context.Context, gameID int32) ([]GetRankingRow, error) {
@@ -313,25 +299,20 @@ func (q *Queries) GetRanking(ctx context.Context, gameID int32) ([]GetRankingRow
for rows.Next() {
var i GetRankingRow
if err := rows.Scan(
- &i.GameID,
- &i.UserID,
- &i.Code,
- &i.Status,
- &i.BestScoreSubmissionID,
- &i.UserID_2,
- &i.Username,
- &i.DisplayName,
- &i.IconPath,
- &i.IsAdmin,
- &i.Label,
- &i.CreatedAt,
- &i.SubmissionID,
- &i.GameID_2,
- &i.UserID_3,
- &i.Code_2,
- &i.CodeSize,
- &i.Status_2,
- &i.CreatedAt_2,
+ &i.Submission.SubmissionID,
+ &i.Submission.GameID,
+ &i.Submission.UserID,
+ &i.Submission.Code,
+ &i.Submission.CodeSize,
+ &i.Submission.Status,
+ &i.Submission.CreatedAt,
+ &i.User.UserID,
+ &i.User.Username,
+ &i.User.DisplayName,
+ &i.User.IconPath,
+ &i.User.IsAdmin,
+ &i.User.Label,
+ &i.User.CreatedAt,
); err != nil {
return nil, err
}
diff --git a/backend/query.sql b/backend/query.sql
index 61175ab..2a95a23 100644
--- a/backend/query.sql
+++ b/backend/query.sql
@@ -123,7 +123,10 @@ LEFT JOIN submissions ON game_states.best_score_submission_id = submissions.subm
WHERE game_main_players.game_id = $1;
-- name: GetRanking :many
-SELECT * FROM game_states
+SELECT
+ sqlc.embed(submissions),
+ sqlc.embed(users)
+FROM game_states
JOIN users ON game_states.user_id = users.user_id
JOIN submissions ON game_states.best_score_submission_id = submissions.submission_id
WHERE game_states.game_id = $1