diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-29 02:59:07 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-29 02:59:07 +0900 |
| commit | d1c8aa42aec32c8b042ae32d249df9c3c969453d (patch) | |
| tree | 2f248715213d12d6649f32b5ddcbb0d9a0281ed8 /backend/api/handlers.go | |
| parent | 22ddf340f0b0c8d0cd04c34d9fa1481a1fbf422f (diff) | |
| parent | 161d82bee9f9e65680516a9cfd392e0cf297eadf (diff) | |
| download | iosdc-japan-2025-albatross-d1c8aa42aec32c8b042ae32d249df9c3c969453d.tar.gz iosdc-japan-2025-albatross-d1c8aa42aec32c8b042ae32d249df9c3c969453d.tar.zst iosdc-japan-2025-albatross-d1c8aa42aec32c8b042ae32d249df9c3c969453d.zip | |
Merge branch 'game-playing'
Diffstat (limited to 'backend/api/handlers.go')
| -rw-r--r-- | backend/api/handlers.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/backend/api/handlers.go b/backend/api/handlers.go index 54a3fc4..91cdbc8 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -133,6 +133,41 @@ func (h *ApiHandler) GetGames(ctx context.Context, request GetGamesRequestObject } } +func (h *ApiHandler) GetGamesGameId(ctx context.Context, request GetGamesGameIdRequestObject) (GetGamesGameIdResponseObject, error) { + // TODO: user permission + // user := ctx.Value("user").(*auth.JWTClaims) + gameId := request.GameId + row, err := h.q.GetGameById(ctx, int32(gameId)) + if err != nil { + return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) + } + var startedAt *int + if row.StartedAt.Valid { + startedAtTimestamp := int(row.StartedAt.Time.Unix()) + startedAt = &startedAtTimestamp + } + var problem *Problem + if row.ProblemID.Valid && GameState(row.State) != Closed && GameState(row.State) != WaitingEntries { + if !row.Title.Valid || !row.Description.Valid { + panic("inconsistent data") + } + problem = &Problem{ + ProblemId: int(row.ProblemID.Int32), + Title: row.Title.String, + Description: row.Description.String, + } + } + game := Game{ + GameId: int(row.GameID), + State: GameState(row.State), + DisplayName: row.DisplayName, + DurationSeconds: int(row.DurationSeconds), + StartedAt: startedAt, + Problem: problem, + } + return GetGamesGameId200JSONResponse(game), nil +} + func _assertJwtPayloadIsCompatibleWithJWTClaims() { var c auth.JWTClaims var p JwtPayload |
