From 47f95342097e8828059053c168e06cd44e0ab43b Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 10 Aug 2024 19:55:28 +0900 Subject: feat(backend): include `verification_steps` in `Game` object --- backend/api/handler.go | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'backend/api/handler.go') diff --git a/backend/api/handler.go b/backend/api/handler.go index 8830d1c..134a4f9 100644 --- a/backend/api/handler.go +++ b/backend/api/handler.go @@ -3,11 +3,13 @@ package api import ( "context" "errors" + "fmt" "log" "net/http" "github.com/jackc/pgx/v5" "github.com/labstack/echo/v4" + "github.com/oapi-codegen/nullable" "github.com/nsfisis/iosdc-japan-2024-albatross/backend/auth" "github.com/nsfisis/iosdc-japan-2024-albatross/backend/db" @@ -149,15 +151,30 @@ func (h *Handler) GetGame(ctx context.Context, request GetGameRequestObject, use IsAdmin: playerRow.IsAdmin, } } + testcaseIDs, err := h.q.ListTestcaseIDsByGameID(ctx, int32(gameID)) + if err != nil { + return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) + } + verificationSteps := make([]VerificationStep, len(testcaseIDs)+1) + verificationSteps[0] = VerificationStep{ + Label: "Compile", + } + for i, testcaseID := range testcaseIDs { + verificationSteps[i+1] = VerificationStep{ + TestcaseID: nullable.NewNullableWithValue(int(testcaseID)), + Label: fmt.Sprintf("Testcase %d", i+1), + } + } game := Game{ - GameID: int(row.GameID), - GameType: GameGameType(row.GameType), - State: GameState(row.State), - DisplayName: row.DisplayName, - DurationSeconds: int(row.DurationSeconds), - StartedAt: startedAt, - Problem: problem, - Players: players, + GameID: int(row.GameID), + GameType: GameGameType(row.GameType), + State: GameState(row.State), + DisplayName: row.DisplayName, + DurationSeconds: int(row.DurationSeconds), + StartedAt: startedAt, + Problem: problem, + Players: players, + VerificationSteps: verificationSteps, } return GetGame200JSONResponse{ Game: game, -- cgit v1.2.3-70-g09d2