From 3e25e9ccf191a2fe092fa07954d14c13885a470e Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 16 Sep 2025 23:12:54 +0900 Subject: feat(backend): prevent game from starting without testcases --- backend/admin/handler.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'backend/admin/handler.go') 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{ -- cgit v1.2.3-70-g09d2