diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-09-05 21:12:03 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-09-05 21:12:03 +0900 |
| commit | 2fb0b6516b9731ca832a31f6b31515f4eb056cb1 (patch) | |
| tree | e2f4f82d783799f84a111179075e3da11cdb9e80 /backend/api/handler.go | |
| parent | 82d3cf35c3c6b85b48c94dd6301c8bf718669b8d (diff) | |
| download | iosdc-japan-2025-albatross-2fb0b6516b9731ca832a31f6b31515f4eb056cb1.tar.gz iosdc-japan-2025-albatross-2fb0b6516b9731ca832a31f6b31515f4eb056cb1.tar.zst iosdc-japan-2025-albatross-2fb0b6516b9731ca832a31f6b31515f4eb056cb1.zip | |
feat(backend): support swift language
Diffstat (limited to 'backend/api/handler.go')
| -rw-r--r-- | backend/api/handler.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/backend/api/handler.go b/backend/api/handler.go index 67f859c..4321d15 100644 --- a/backend/api/handler.go +++ b/backend/api/handler.go @@ -21,8 +21,8 @@ type Handler struct { } type GameHubInterface interface { - CalcCodeSize(code string) int - EnqueueTestTasks(ctx context.Context, submissionID, gameID, userID int, code string) error + CalcCodeSize(code string, language string) int + EnqueueTestTasks(ctx context.Context, submissionID, gameID, userID int, language, code string) error } func (h *Handler) PostLogin(ctx context.Context, request PostLoginRequestObject) (PostLoginResponseObject, error) { @@ -88,6 +88,7 @@ func (h *Handler) GetGames(ctx context.Context, _ GetGamesRequestObject, _ *auth ProblemID: int(row.ProblemID), Title: row.Title, Description: row.Description, + Language: ProblemLanguage(*row.Language), SampleCode: row.SampleCode, }, } @@ -166,6 +167,7 @@ func (h *Handler) GetGame(ctx context.Context, request GetGameRequestObject, _ * ProblemID: int(row.ProblemID), Title: row.Title, Description: row.Description, + Language: ProblemLanguage(*row.Language), SampleCode: row.SampleCode, }, MainPlayers: mainPlayers, @@ -294,10 +296,20 @@ func (h *Handler) PostGamePlaySubmit(ctx context.Context, request PostGamePlaySu gameID := request.GameID userID := user.UserID code := request.Body.Code - codeSize := h.hub.CalcCodeSize(code) + + gameRow, err := h.q.GetGameByID(ctx, int32(gameID)) + if err != nil { + if errors.Is(err, pgx.ErrNoRows) { + return PostGamePlaySubmit404JSONResponse{}, nil + } + return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) + } + + language := *gameRow.Language + codeSize := h.hub.CalcCodeSize(code, language) // TODO: check if the game is running // TODO: transaction - err := h.q.UpdateCodeAndStatus(ctx, db.UpdateCodeAndStatusParams{ + err = h.q.UpdateCodeAndStatus(ctx, db.UpdateCodeAndStatusParams{ GameID: int32(gameID), UserID: int32(userID), Code: code, @@ -315,7 +327,7 @@ func (h *Handler) PostGamePlaySubmit(ctx context.Context, request PostGamePlaySu if err != nil { return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) } - err = h.hub.EnqueueTestTasks(ctx, int(submissionID), gameID, userID, code) + err = h.hub.EnqueueTestTasks(ctx, int(submissionID), gameID, userID, language, code) if err != nil { return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) } |
