diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-04-02 01:13:37 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-04-02 01:13:37 +0900 |
| commit | 9f8a609ece9093d3aaa62937c8035903bbd8a045 (patch) | |
| tree | cc329ca4e5ef24496e8b9a542b537d0354623fd9 /backend/admin/handler.go | |
| parent | 626ab209bc5b1b9f3a608a1c2a536ead3cd27a7f (diff) | |
| download | phperkaigi-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
Diffstat (limited to 'backend/admin/handler.go')
| -rw-r--r-- | backend/admin/handler.go | 38 |
1 files changed, 38 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") +} |
