diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-01 21:09:36 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-01 21:09:36 +0900 |
| commit | 72012983718a8d1f1d850e24e9af3a29fb20374a (patch) | |
| tree | 1037105dac7a24ce8850ad4a8d5b0b62fb5134d4 /backend | |
| parent | 6767acd3d9cc2cf5b778048ec6339b8c9123fbb5 (diff) | |
| download | iosdc-japan-2024-albatross-72012983718a8d1f1d850e24e9af3a29fb20374a.tar.gz iosdc-japan-2024-albatross-72012983718a8d1f1d850e24e9af3a29fb20374a.tar.zst iosdc-japan-2024-albatross-72012983718a8d1f1d850e24e9af3a29fb20374a.zip | |
refactor: remove `player_id` parameter from `/api/games`
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/api/generated.go | 59 | ||||
| -rw-r--r-- | backend/api/handlers.go | 99 |
2 files changed, 53 insertions, 105 deletions
diff --git a/backend/api/generated.go b/backend/api/generated.go index fe693f8..6de100a 100644 --- a/backend/api/generated.go +++ b/backend/api/generated.go @@ -241,7 +241,6 @@ type AdminGetUsersParams struct { // GetGamesParams defines parameters for GetGames. type GetGamesParams struct { - PlayerId *int `form:"player_id,omitempty" json:"player_id,omitempty"` Authorization string `json:"Authorization"` } @@ -806,12 +805,6 @@ func (w *ServerInterfaceWrapper) GetGames(ctx echo.Context) error { // Parameter object where we will unmarshal all parameters from the context var params GetGamesParams - // ------------- Optional query parameter "player_id" ------------- - - err = runtime.BindQueryParameter("form", true, false, "player_id", ctx.QueryParams(), ¶ms.PlayerId) - if err != nil { - return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter player_id: %s", err)) - } headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- @@ -1561,32 +1554,32 @@ func (sh *strictHandler) GetToken(ctx echo.Context, params GetTokenParams) error // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+xZbW/bNhD+Kxo3oBugxY4T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D2ubL6nS9Y8AsHl6Uk4mySYrVoivRIgucge/d8wc7u07lT", + "VE5wnJCmf2eYypr8U84pYKZXZ9JRXobnLo/qpW0rNJSd/ix3WVHSuiyqcLd9q9URNuNmgLVxRZd0ipXg", + "UgYaomCYBg8wDS7Hr1CIPoCQJsVQ/2xw1tfoeQoMpwSN0PlZ/6yPQqTda0LUM/v25jixIZuDIYWOorm+", + "ehXr/fSaa1DXZpWWFjgBBUKa3kj7Gy0AxyBQiKyb0GWmFlyQf40WtOoSW4ttEanH8tp9d3qxTDmTFtKw", + "3y8KiAJm0OE0pSQymnv30tKp1tfMwcoyoiCRPiWtrloIC4GXzrs/uSFUDZKj10SqgM8CK5GH6KI/OMKW", + "pO556yS8Zbhwtce1ZanBB3xDscF+3jX2X7mYkjgGFlQJ16kJlX6jRWZJgsWyjEsRlDxskKD3sbjazb3o", + "sIENpnxVXKgvi3eyYOXIeQLE8qOTgz5e0bs0ITrR5kvSRuO/6Br/n1wFM56xbh1fa22S/RpUgKtUSrNN", + "jB5nT5PR7zOQ6mdub7wPDNPn+ri4uYv1mtV2fD30m/e+kq+JjnxuBj5vleuL1hiBbuxkOssoXQZZGmNV", + "Vp1+16x9xT5gSuKgyLhOubuu+1TzTzX/mJp/a5hQlf26x9Mz2O5B59aselqDTmWZ16BjBvZdg45Vuc+g", + "YyVO7P2qBh1MaRkYTYTts/5pzD+N+d/qmO874J9m+9Nsf+rzntpsrxlO+dze/qdcOog95lK9Nku6GpxT", + "LOUDF/Ha9+Xi6WB47pqcj/yawMraVGx9d9AweUx9UPwfWPuI9aj/na38v/u7nlHiE/3GkKsZCExpqCUJ", + "B59q1I0ExHovTOUnGXfLaAZcBFU41yYZCSKwaW0yvHL9ppPrrVnwtLq3bz2fPtOB5CiNcsGF+pGSDxAH", + "2FgdWD/leZ7/FwAA///GgvoRhDAAAA==", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/backend/api/handlers.go b/backend/api/handlers.go index ea9ddea..164682d 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -240,85 +240,40 @@ func (h *ApiHandler) GetToken(ctx context.Context, request GetTokenRequestObject } func (h *ApiHandler) GetGames(ctx context.Context, request GetGamesRequestObject, user *auth.JWTClaims) (GetGamesResponseObject, error) { - playerId := request.Params.PlayerId - if !user.IsAdmin { - if playerId == nil || *playerId != user.UserID { - return GetGames403JSONResponse{ - Message: "Forbidden", - }, nil - } + gameRows, err := h.q.ListGamesForPlayer(ctx, int32(user.UserID)) + if err != nil { + return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) } - if playerId == nil { - gameRows, err := h.q.ListGames(ctx) - if err != nil { - return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) + games := make([]Game, len(gameRows)) + for i, row := range gameRows { + var startedAt *int + if row.StartedAt.Valid { + startedAtTimestamp := int(row.StartedAt.Time.Unix()) + startedAt = &startedAtTimestamp } - games := make([]Game, len(gameRows)) - for i, row := range gameRows { - var startedAt *int - if row.StartedAt.Valid { - startedAtTimestamp := int(row.StartedAt.Time.Unix()) - startedAt = &startedAtTimestamp - } - var problem *Problem - if row.ProblemID != nil { - if row.Title == nil || row.Description == nil { - panic("inconsistent data") - } - problem = &Problem{ - ProblemId: int(*row.ProblemID), - Title: *row.Title, - Description: *row.Description, - } + var problem *Problem + if row.ProblemID != nil { + if row.Title == nil || row.Description == nil { + panic("inconsistent data") } - games[i] = Game{ - GameId: int(row.GameID), - State: GameState(row.State), - DisplayName: row.DisplayName, - DurationSeconds: int(row.DurationSeconds), - StartedAt: startedAt, - Problem: problem, + problem = &Problem{ + ProblemId: int(*row.ProblemID), + Title: *row.Title, + Description: *row.Description, } } - return GetGames200JSONResponse{ - Games: games, - }, nil - } else { - gameRows, err := h.q.ListGamesForPlayer(ctx, int32(*playerId)) - if err != nil { - return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) - } - games := make([]Game, len(gameRows)) - for i, row := range gameRows { - var startedAt *int - if row.StartedAt.Valid { - startedAtTimestamp := int(row.StartedAt.Time.Unix()) - startedAt = &startedAtTimestamp - } - var problem *Problem - if row.ProblemID != nil { - if row.Title == nil || row.Description == nil { - panic("inconsistent data") - } - problem = &Problem{ - ProblemId: int(*row.ProblemID), - Title: *row.Title, - Description: *row.Description, - } - } - games[i] = Game{ - GameId: int(row.GameID), - State: GameState(row.State), - DisplayName: row.DisplayName, - DurationSeconds: int(row.DurationSeconds), - StartedAt: startedAt, - Problem: problem, - } + games[i] = Game{ + GameId: int(row.GameID), + State: GameState(row.State), + DisplayName: row.DisplayName, + DurationSeconds: int(row.DurationSeconds), + StartedAt: startedAt, + Problem: problem, } - return GetGames200JSONResponse{ - Games: games, - }, nil } + return GetGames200JSONResponse{ + Games: games, + }, nil } func (h *ApiHandler) GetGame(ctx context.Context, request GetGameRequestObject, user *auth.JWTClaims) (GetGameResponseObject, error) { |
