From daaf81ae931654e20f882fbc6bbc4a02cbfc0273 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 28 Jul 2024 20:09:09 +0900 Subject: feat(backend): partially implement gaming --- backend/api/handlers.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'backend/api/handlers.go') 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 -- cgit v1.2.3-70-g09d2