aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/api
diff options
context:
space:
mode:
Diffstat (limited to 'backend/api')
-rw-r--r--backend/api/generated.go110
-rw-r--r--backend/api/handlers.go12
2 files changed, 64 insertions, 58 deletions
diff --git a/backend/api/generated.go b/backend/api/generated.go
index 6de100a..47dd905 100644
--- a/backend/api/generated.go
+++ b/backend/api/generated.go
@@ -207,14 +207,20 @@ type User struct {
Username string `json:"username"`
}
+// HeaderAuthorization defines model for header_authorization.
+type HeaderAuthorization = string
+
+// PathGameId defines model for path_game_id.
+type PathGameId = int
+
// AdminGetGamesParams defines parameters for AdminGetGames.
type AdminGetGamesParams struct {
- Authorization string `json:"Authorization"`
+ Authorization HeaderAuthorization `json:"Authorization"`
}
// AdminGetGameParams defines parameters for AdminGetGame.
type AdminGetGameParams struct {
- Authorization string `json:"Authorization"`
+ Authorization HeaderAuthorization `json:"Authorization"`
}
// AdminPutGameJSONBody defines parameters for AdminPutGame.
@@ -228,7 +234,7 @@ type AdminPutGameJSONBody struct {
// AdminPutGameParams defines parameters for AdminPutGame.
type AdminPutGameParams struct {
- Authorization string `json:"Authorization"`
+ Authorization HeaderAuthorization `json:"Authorization"`
}
// AdminPutGameJSONBodyState defines parameters for AdminPutGame.
@@ -236,17 +242,17 @@ type AdminPutGameJSONBodyState string
// AdminGetUsersParams defines parameters for AdminGetUsers.
type AdminGetUsersParams struct {
- Authorization string `json:"Authorization"`
+ Authorization HeaderAuthorization `json:"Authorization"`
}
// GetGamesParams defines parameters for GetGames.
type GetGamesParams struct {
- Authorization string `json:"Authorization"`
+ Authorization HeaderAuthorization `json:"Authorization"`
}
// GetGameParams defines parameters for GetGame.
type GetGameParams struct {
- Authorization string `json:"Authorization"`
+ Authorization HeaderAuthorization `json:"Authorization"`
}
// PostLoginJSONBody defines parameters for PostLogin.
@@ -257,7 +263,7 @@ type PostLoginJSONBody struct {
// GetTokenParams defines parameters for GetToken.
type GetTokenParams struct {
- Authorization string `json:"Authorization"`
+ Authorization HeaderAuthorization `json:"Authorization"`
}
// AdminPutGameJSONRequestBody defines body for AdminPutGame for application/json ContentType.
@@ -635,10 +641,10 @@ type ServerInterface interface {
AdminGetGames(ctx echo.Context, params AdminGetGamesParams) error
// Get a game
// (GET /admin/games/{game_id})
- AdminGetGame(ctx echo.Context, gameId int, params AdminGetGameParams) error
+ AdminGetGame(ctx echo.Context, gameId PathGameId, params AdminGetGameParams) error
// Update a game
// (PUT /admin/games/{game_id})
- AdminPutGame(ctx echo.Context, gameId int, params AdminPutGameParams) error
+ AdminPutGame(ctx echo.Context, gameId PathGameId, params AdminPutGameParams) error
// List all users
// (GET /admin/users)
AdminGetUsers(ctx echo.Context, params AdminGetUsersParams) error
@@ -647,7 +653,7 @@ type ServerInterface interface {
GetGames(ctx echo.Context, params GetGamesParams) error
// Get a game
// (GET /games/{game_id})
- GetGame(ctx echo.Context, gameId int, params GetGameParams) error
+ GetGame(ctx echo.Context, gameId PathGameId, params GetGameParams) error
// User login
// (POST /login)
PostLogin(ctx echo.Context) error
@@ -671,7 +677,7 @@ func (w *ServerInterfaceWrapper) AdminGetGames(ctx echo.Context) error {
headers := ctx.Request().Header
// ------------- Required header parameter "Authorization" -------------
if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found {
- var Authorization string
+ var Authorization HeaderAuthorization
n := len(valueList)
if n != 1 {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n))
@@ -696,7 +702,7 @@ func (w *ServerInterfaceWrapper) AdminGetGames(ctx echo.Context) error {
func (w *ServerInterfaceWrapper) AdminGetGame(ctx echo.Context) error {
var err error
// ------------- Path parameter "game_id" -------------
- var gameId int
+ var gameId PathGameId
err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
@@ -709,7 +715,7 @@ func (w *ServerInterfaceWrapper) AdminGetGame(ctx echo.Context) error {
headers := ctx.Request().Header
// ------------- Required header parameter "Authorization" -------------
if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found {
- var Authorization string
+ var Authorization HeaderAuthorization
n := len(valueList)
if n != 1 {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n))
@@ -734,7 +740,7 @@ func (w *ServerInterfaceWrapper) AdminGetGame(ctx echo.Context) error {
func (w *ServerInterfaceWrapper) AdminPutGame(ctx echo.Context) error {
var err error
// ------------- Path parameter "game_id" -------------
- var gameId int
+ var gameId PathGameId
err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
@@ -747,7 +753,7 @@ func (w *ServerInterfaceWrapper) AdminPutGame(ctx echo.Context) error {
headers := ctx.Request().Header
// ------------- Required header parameter "Authorization" -------------
if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found {
- var Authorization string
+ var Authorization HeaderAuthorization
n := len(valueList)
if n != 1 {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n))
@@ -778,7 +784,7 @@ func (w *ServerInterfaceWrapper) AdminGetUsers(ctx echo.Context) error {
headers := ctx.Request().Header
// ------------- Required header parameter "Authorization" -------------
if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found {
- var Authorization string
+ var Authorization HeaderAuthorization
n := len(valueList)
if n != 1 {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n))
@@ -809,7 +815,7 @@ func (w *ServerInterfaceWrapper) GetGames(ctx echo.Context) error {
headers := ctx.Request().Header
// ------------- Required header parameter "Authorization" -------------
if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found {
- var Authorization string
+ var Authorization HeaderAuthorization
n := len(valueList)
if n != 1 {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n))
@@ -834,7 +840,7 @@ func (w *ServerInterfaceWrapper) GetGames(ctx echo.Context) error {
func (w *ServerInterfaceWrapper) GetGame(ctx echo.Context) error {
var err error
// ------------- Path parameter "game_id" -------------
- var gameId int
+ var gameId PathGameId
err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
@@ -847,7 +853,7 @@ func (w *ServerInterfaceWrapper) GetGame(ctx echo.Context) error {
headers := ctx.Request().Header
// ------------- Required header parameter "Authorization" -------------
if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found {
- var Authorization string
+ var Authorization HeaderAuthorization
n := len(valueList)
if n != 1 {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n))
@@ -887,7 +893,7 @@ func (w *ServerInterfaceWrapper) GetToken(ctx echo.Context) error {
headers := ctx.Request().Header
// ------------- Required header parameter "Authorization" -------------
if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found {
- var Authorization string
+ var Authorization HeaderAuthorization
n := len(valueList)
if n != 1 {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n))
@@ -989,7 +995,7 @@ func (response AdminGetGames403JSONResponse) VisitAdminGetGamesResponse(w http.R
}
type AdminGetGameRequestObject struct {
- GameId int `json:"game_id"`
+ GameId PathGameId `json:"game_id"`
Params AdminGetGameParams
}
@@ -1042,7 +1048,7 @@ func (response AdminGetGame404JSONResponse) VisitAdminGetGameResponse(w http.Res
}
type AdminPutGameRequestObject struct {
- GameId int `json:"game_id"`
+ GameId PathGameId `json:"game_id"`
Params AdminPutGameParams
Body *AdminPutGameJSONRequestBody
}
@@ -1186,7 +1192,7 @@ func (response GetGames403JSONResponse) VisitGetGamesResponse(w http.ResponseWri
}
type GetGameRequestObject struct {
- GameId int `json:"game_id"`
+ GameId PathGameId `json:"game_id"`
Params GetGameParams
}
@@ -1364,7 +1370,7 @@ func (sh *strictHandler) AdminGetGames(ctx echo.Context, params AdminGetGamesPar
}
// AdminGetGame operation middleware
-func (sh *strictHandler) AdminGetGame(ctx echo.Context, gameId int, params AdminGetGameParams) error {
+func (sh *strictHandler) AdminGetGame(ctx echo.Context, gameId PathGameId, params AdminGetGameParams) error {
var request AdminGetGameRequestObject
request.GameId = gameId
@@ -1390,7 +1396,7 @@ func (sh *strictHandler) AdminGetGame(ctx echo.Context, gameId int, params Admin
}
// AdminPutGame operation middleware
-func (sh *strictHandler) AdminPutGame(ctx echo.Context, gameId int, params AdminPutGameParams) error {
+func (sh *strictHandler) AdminPutGame(ctx echo.Context, gameId PathGameId, params AdminPutGameParams) error {
var request AdminPutGameRequestObject
request.GameId = gameId
@@ -1472,7 +1478,7 @@ func (sh *strictHandler) GetGames(ctx echo.Context, params GetGamesParams) error
}
// GetGame operation middleware
-func (sh *strictHandler) GetGame(ctx echo.Context, gameId int, params GetGameParams) error {
+func (sh *strictHandler) GetGame(ctx echo.Context, gameId PathGameId, params GetGameParams) error {
var request GetGameRequestObject
request.GameId = gameId
@@ -1554,32 +1560,32 @@ func (sh *strictHandler) GetToken(ctx echo.Context, params GetTokenParams) error
// Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{
- "H4sIAAAAAAAC/+xZa2/bNhf+K3r5DugGaPElQdH5W5Z1WYduM5oG+1AEBi0d28woUiWpJl6h/z6Q1MWy",
- "aJu21UsK90OTSDyHz7k8h+dQH1HEk5QzYEqi0UckowUk2Px6jRPQP1PBUxCKgHkaE5lSvJyw4i084iSl",
- "gEZmfTBAIVLLVP8tlSBsjvIQxZnAinA2kRBxFsuG3PnzfiVCmII5CC0zxwlMSNxYOnAtTAWfUkj0wu8E",
- "zNAI/b9X29QrDOqNi2V5iKTCQkE8waqh/aeL589fXLzoO+FIhZW1l2UJGr1DEeUSYhSiB0wUYfMJMCW0",
- "j+onZh+kEUKKBaBiZ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c3x4l12RxMUmgv",
+ "muurd7HeT9Ncgro0VGHj9nVDb1ST9Jy3s/mNtpJMOZN242G/X5QJBcxgwGlKSWTIe7fSJk19h9qMtAo/",
+ "UZBIn8JV1yaEhcBL5w2f3OCQRiqj90SqgM8Cy5GH6Kw/eIQuSd3Z1qF2zUr7eVxOlhJ8wDcEG+ynXWP/",
+ "mYspiWNgQRVWnapQyTdSZJYkWCxLvxROycNGqPceigvc3CvoO4r5cCdf44HhK+SIX2Y4MsHLEefG2scM",
+ "eM4M0PjPusb/O1fBjGesW8PXUpt5ewkqwFUopdmm5Bxnz56cnzOQ6kdub5sPtPhTPext7iC95qQdL3d+",
+ "s9YLeclzhGbztTZvVd6zVguPruxUOMsoXQZZGmNVFpB+1wn4jn3BlMRBEXGdpuG67GP5Ppbvx5Tva5MJ",
+ "VQWvOy89/+weMq4N1UscMir8XkOGGYl3DRlW5D5DhuU45uiLGjIwpaVjdLhvn6aPg/RxkP53D9K+I/Rx",
+ "ej5Oz8f26xmnZ52slM/thXjKpSNHx1yq94akq3k2xVLecRGvPbkWXwfDU9dA+8gLdlaWmWLrm4NmvMfU",
+ "B8X/grV3nXv972Tl/91PXUaIj/cbs6fOQGBKQy2TcPC1JtBIQKz3wlR+lSm09GbARVC5c23AkCACG9Ym",
+ "wivTbzqEPhqCl9hu/dej5omOHUcBlAsu1PeUfIE4wEbrwNopz/P8nwAAAP//7jff808wAAA=",
}
// GetSwagger returns the content of the embedded swagger specification file
diff --git a/backend/api/handlers.go b/backend/api/handlers.go
index 164682d..26f7a7d 100644
--- a/backend/api/handlers.go
+++ b/backend/api/handlers.go
@@ -61,8 +61,8 @@ func (h *ApiHandler) AdminGetGames(ctx context.Context, request AdminGetGamesReq
}
func (h *ApiHandler) AdminGetGame(ctx context.Context, request AdminGetGameRequestObject, user *auth.JWTClaims) (AdminGetGameResponseObject, error) {
- gameId := request.GameId
- row, err := h.q.GetGameById(ctx, int32(gameId))
+ gameID := request.GameId
+ row, err := h.q.GetGameById(ctx, int32(gameID))
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return AdminGetGame404JSONResponse{
@@ -205,14 +205,14 @@ func (h *ApiHandler) AdminGetUsers(ctx context.Context, request AdminGetUsersReq
func (h *ApiHandler) PostLogin(ctx context.Context, request PostLoginRequestObject) (PostLoginResponseObject, error) {
username := request.Body.Username
password := request.Body.Password
- userId, err := auth.Login(ctx, h.q, username, password)
+ userID, err := auth.Login(ctx, h.q, username, password)
if err != nil {
return PostLogin401JSONResponse{
Message: "Invalid username or password",
}, nil
}
- user, err := h.q.GetUserById(ctx, int32(userId))
+ user, err := h.q.GetUserById(ctx, int32(userID))
if err != nil {
return PostLogin401JSONResponse{
Message: "Invalid username or password",
@@ -278,8 +278,8 @@ func (h *ApiHandler) GetGames(ctx context.Context, request GetGamesRequestObject
func (h *ApiHandler) GetGame(ctx context.Context, request GetGameRequestObject, user *auth.JWTClaims) (GetGameResponseObject, error) {
// TODO: check user permission
- gameId := request.GameId
- row, err := h.q.GetGameById(ctx, int32(gameId))
+ gameID := request.GameId
+ row, err := h.q.GetGameById(ctx, int32(gameID))
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return GetGame404JSONResponse{