aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-04-02 01:13:37 +0900
committernsfisis <nsfisis@gmail.com>2025-04-02 01:13:37 +0900
commit9f8a609ece9093d3aaa62937c8035903bbd8a045 (patch)
treecc329ca4e5ef24496e8b9a542b537d0354623fd9
parent626ab209bc5b1b9f3a608a1c2a536ead3cd27a7f (diff)
downloadphperkaigi-2025-albatross-9f8a609ece9093d3aaa62937c8035903bbd8a045.tar.gz
phperkaigi-2025-albatross-9f8a609ece9093d3aaa62937c8035903bbd8a045.tar.zst
phperkaigi-2025-albatross-9f8a609ece9093d3aaa62937c8035903bbd8a045.zip
feat(backend): add admin tool to fix submission status
-rw-r--r--backend/admin/handler.go38
-rw-r--r--backend/admin/templates/dashboard.html3
-rw-r--r--backend/db/query.sql.go53
-rw-r--r--backend/query.sql6
4 files changed, 100 insertions, 0 deletions
diff --git a/backend/admin/handler.go b/backend/admin/handler.go
index 123e6f4..eaea208 100644
--- a/backend/admin/handler.go
+++ b/backend/admin/handler.go
@@ -64,6 +64,7 @@ func (h *Handler) RegisterHandlers(g *echo.Group) {
g.POST("/games/:gameID", h.postGameEdit)
g.POST("/games/:gameID/start", h.postGameStart)
g.GET("/online-qualifying-ranking", h.getOnlineQualifyingRanking)
+ g.POST("/fix", h.postFix)
}
func (h *Handler) getDashboard(c echo.Context) error {
@@ -428,3 +429,40 @@ func (h *Handler) getOnlineQualifyingRanking(c echo.Context) error {
"Entries": entries,
})
}
+
+func (h *Handler) postFix(c echo.Context) error {
+ rows, err := h.q.ListSubmissionIDs(c.Request().Context())
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
+ }
+ for _, submissionID := range rows {
+ as, err := h.q.AggregateTestcaseResults(c.Request().Context(), submissionID)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
+ }
+ err = h.q.UpdateSubmissionStatus(c.Request().Context(), db.UpdateSubmissionStatusParams{
+ SubmissionID: submissionID,
+ Status: as,
+ })
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
+ }
+ }
+
+ rows2, err := h.q.ListGameStateIDs(c.Request().Context())
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
+ }
+ for _, r := range rows2 {
+ gameID := r.GameID
+ userID := r.UserID
+ err := h.q.SyncGameStateBestScoreSubmission(c.Request().Context(), db.SyncGameStateBestScoreSubmissionParams{
+ GameID: gameID,
+ UserID: userID,
+ })
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
+ }
+ }
+ return c.Redirect(http.StatusSeeOther, basePath+"/admin")
+}
diff --git a/backend/admin/templates/dashboard.html b/backend/admin/templates/dashboard.html
index 2d030ef..17a0d6a 100644
--- a/backend/admin/templates/dashboard.html
+++ b/backend/admin/templates/dashboard.html
@@ -10,6 +10,9 @@
<p>
<a href="{{ .BasePath }}/admin/online-qualifying-ranking?game_1=7&game_2=8">Online Qualifying Ranking</a>
</p>
+<form method="post" action="{{ .BasePath }}/fix">
+ <button type="submit">fix</button>
+</form>
<form method="post" action="{{ .BasePath }}/logout">
<button type="submit">Logout</button>
</form>
diff --git a/backend/db/query.sql.go b/backend/db/query.sql.go
index fece99f..d4e134f 100644
--- a/backend/db/query.sql.go
+++ b/backend/db/query.sql.go
@@ -496,6 +496,35 @@ func (q *Queries) ListAllGames(ctx context.Context) ([]Game, error) {
return items, nil
}
+const listGameStateIDs = `-- name: ListGameStateIDs :many
+SELECT game_id, user_id FROM game_states
+`
+
+type ListGameStateIDsRow struct {
+ GameID int32
+ UserID int32
+}
+
+func (q *Queries) ListGameStateIDs(ctx context.Context) ([]ListGameStateIDsRow, error) {
+ rows, err := q.db.Query(ctx, listGameStateIDs)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var items []ListGameStateIDsRow
+ for rows.Next() {
+ var i ListGameStateIDsRow
+ if err := rows.Scan(&i.GameID, &i.UserID); err != nil {
+ return nil, err
+ }
+ items = append(items, i)
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return items, nil
+}
+
const listMainPlayers = `-- name: ListMainPlayers :many
SELECT game_id, game_main_players.user_id, users.user_id, username, display_name, icon_path, is_admin, label, created_at FROM game_main_players
JOIN users ON game_main_players.user_id = users.user_id
@@ -600,6 +629,30 @@ func (q *Queries) ListPublicGames(ctx context.Context) ([]ListPublicGamesRow, er
return items, nil
}
+const listSubmissionIDs = `-- name: ListSubmissionIDs :many
+SELECT submission_id FROM submissions
+`
+
+func (q *Queries) ListSubmissionIDs(ctx context.Context) ([]int32, error) {
+ rows, err := q.db.Query(ctx, listSubmissionIDs)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var items []int32
+ for rows.Next() {
+ var submission_id int32
+ if err := rows.Scan(&submission_id); err != nil {
+ return nil, err
+ }
+ items = append(items, submission_id)
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return items, nil
+}
+
const listTestcasesByGameID = `-- name: ListTestcasesByGameID :many
SELECT testcase_id, problem_id, stdin, stdout FROM testcases
WHERE testcases.problem_id = (SELECT problem_id FROM games WHERE game_id = $1)
diff --git a/backend/query.sql b/backend/query.sql
index 49fe2c1..4a06ee7 100644
--- a/backend/query.sql
+++ b/backend/query.sql
@@ -188,3 +188,9 @@ SET best_score_submission_id = (
LIMIT 1
)
WHERE game_id = $1 AND user_id = $2;
+
+-- name: ListSubmissionIDs :many
+SELECT submission_id FROM submissions;
+
+-- name: ListGameStateIDs :many
+SELECT game_id, user_id FROM game_states;