aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/admin/handler.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-09-16 23:12:54 +0900
committernsfisis <nsfisis@gmail.com>2025-09-16 23:12:54 +0900
commit3e25e9ccf191a2fe092fa07954d14c13885a470e (patch)
treee7fc4c1619e4c2d8c6717344039db68b17739a62 /backend/admin/handler.go
parentba9b11647f4816ca7c4b4ffb6b9859dcc8adb639 (diff)
downloadiosdc-japan-2025-albatross-3e25e9ccf191a2fe092fa07954d14c13885a470e.tar.gz
iosdc-japan-2025-albatross-3e25e9ccf191a2fe092fa07954d14c13885a470e.tar.zst
iosdc-japan-2025-albatross-3e25e9ccf191a2fe092fa07954d14c13885a470e.zip
feat(backend): prevent game from starting without testcases
Diffstat (limited to 'backend/admin/handler.go')
-rw-r--r--backend/admin/handler.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/backend/admin/handler.go b/backend/admin/handler.go
index 289a598..2a50cb0 100644
--- a/backend/admin/handler.go
+++ b/backend/admin/handler.go
@@ -542,6 +542,24 @@ func (h *Handler) postGameStart(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid game id")
}
+ game, err := h.q.GetGameByID(c.Request().Context(), int32(gameID))
+ if err != nil {
+ if errors.Is(err, pgx.ErrNoRows) {
+ return echo.NewHTTPError(http.StatusNotFound, "Game not found")
+ }
+ return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
+ }
+ testcases, err := h.q.ListTestcasesByProblemID(c.Request().Context(), game.ProblemID)
+ if err != nil {
+ if errors.Is(err, pgx.ErrNoRows) {
+ return echo.NewHTTPError(http.StatusBadRequest, "No testcases")
+ }
+ return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
+ }
+ if len(testcases) == 0 {
+ return echo.NewHTTPError(http.StatusBadRequest, "No testcases")
+ }
+
startedAt := time.Now().Add(10 * time.Second)
err = h.q.UpdateGameStartedAt(c.Request().Context(), db.UpdateGameStartedAtParams{