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 | |
| 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')
| -rw-r--r-- | backend/api/generated.go | 67 | ||||
| -rw-r--r-- | backend/api/handler.go | 22 |
2 files changed, 56 insertions, 33 deletions
diff --git a/backend/api/generated.go b/backend/api/generated.go index 8a74b01..15f1c17 100644 --- a/backend/api/generated.go +++ b/backend/api/generated.go @@ -39,6 +39,12 @@ const ( N1V1 GameGameType = "1v1" ) +// Defines values for ProblemLanguage. +const ( + Php ProblemLanguage = "php" + Swift ProblemLanguage = "swift" +) + // Error defines model for Error. type Error struct { Message string `json:"message"` @@ -72,12 +78,16 @@ type LatestGameState struct { // Problem defines model for Problem. type Problem struct { - Description string `json:"description"` - ProblemID int `json:"problem_id"` - SampleCode string `json:"sample_code"` - Title string `json:"title"` + Description string `json:"description"` + Language ProblemLanguage `json:"language"` + ProblemID int `json:"problem_id"` + SampleCode string `json:"sample_code"` + Title string `json:"title"` } +// ProblemLanguage defines model for Problem.Language. +type ProblemLanguage string + // RankingEntry defines model for RankingEntry. type RankingEntry struct { Code nullable.Nullable[string] `json:"code"` @@ -1130,30 +1140,31 @@ func (sh *strictHandler) PostLogin(ctx echo.Context) error { // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+xYW2/UuBf/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7EYEG+aFKWL21xYsGg0GbLl6mZqGBWzpsTWrN8y8D1+J7sgiOOxUHwYTxMly", + "eat21odoq/qstsL2aqO2IlDc1UQU/Cb5FVUaiQ1yFFWEz5bHUyq0Ni/81toQnR4m6k0gNn3kOTF5z6lQ", + "y6+iOpSLL3WDUh0K6jeKaXSQzptH7wED8yIfiPSsQF9aF3+3CBuKs8MU7SDqQ+IFaERqhQOQWJjks2gK", + "ZCFUAB0r4drNFSP7X1z79I/BxM6NT0W6/wqE3LHhCTWSYbj4LyhVGN4+pt66kXJTMrZHZZES3YDlX48w", + "Aw+kM0DMDibIOmYaa+5UrJrZ5aaEZBDnxh036vwI+ak1/KYENZzxhuBzTOYkqz9FKZvIGIuQI304yauH", + "LGhmOyRBlUyjjZCo7nKnAee63nnp7a07+1+Cu98E1w4iDwSHDhYWivXTYRBuO6KTzEtwB/voPwxJL8Wp", + "HyfH2V8kTakhIWzlnbhV8htjMJAN5zXpl4z1M0qXEZVp3c1OTihHzfvbA+rxbmnYNH6le0uZhdz63eWH", + "AG3P7lnjo/fmdGiMbJjPwejKxgg1JA+yVBcDGwzcmNi6x5zpOvzKHvlWdbAgSu2E9N912tXjk1M88Rb0", + "FQ88vJmja9FfUUDvaLUWH2Hw/Hxt/o56/w+a4pjMQatX2A0CgWuj6p2LuwerdwokcsCpqqr6OwAA///J", + "KoN2UB8AAA==", } // GetSwagger returns the content of the embedded swagger specification file 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()) } |
