aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-04 20:48:50 +0900
committernsfisis <nsfisis@gmail.com>2024-08-04 20:48:50 +0900
commitf4bae7f755ca25b2547dc98b2db2fdb255948bc5 (patch)
tree4690c2aabafaedb50f86ece4900c9616d9518947 /backend
parent3963dedada8fdc43b18dfec1313c184d2f4fdc47 (diff)
downloadiosdc-japan-2024-albatross-f4bae7f755ca25b2547dc98b2db2fdb255948bc5.tar.gz
iosdc-japan-2024-albatross-f4bae7f755ca25b2547dc98b2db2fdb255948bc5.tar.zst
iosdc-japan-2024-albatross-f4bae7f755ca25b2547dc98b2db2fdb255948bc5.zip
chore: remove admin APIs to communicate between app-server and api-server
Diffstat (limited to 'backend')
-rw-r--r--backend/api/generated.go561
-rw-r--r--backend/api/handler_wrapper.go76
-rw-r--r--backend/api/handlers.go189
-rw-r--r--backend/game/models.go14
4 files changed, 40 insertions, 800 deletions
diff --git a/backend/api/generated.go b/backend/api/generated.go
index f7da9ee..ea1c315 100644
--- a/backend/api/generated.go
+++ b/backend/api/generated.go
@@ -24,13 +24,13 @@ import (
// Defines values for GameState.
const (
- GameStateClosed GameState = "closed"
- GameStateFinished GameState = "finished"
- GameStateGaming GameState = "gaming"
- GameStatePrepare GameState = "prepare"
- GameStateStarting GameState = "starting"
- GameStateWaitingEntries GameState = "waiting_entries"
- GameStateWaitingStart GameState = "waiting_start"
+ Closed GameState = "closed"
+ Finished GameState = "finished"
+ Gaming GameState = "gaming"
+ Prepare GameState = "prepare"
+ Starting GameState = "starting"
+ WaitingEntries GameState = "waiting_entries"
+ WaitingStart GameState = "waiting_start"
)
// Defines values for GamePlayerMessageS2CExecResultPayloadStatus.
@@ -43,17 +43,6 @@ const (
GameWatcherMessageS2CExecResultPayloadStatusSuccess GameWatcherMessageS2CExecResultPayloadStatus = "success"
)
-// Defines values for AdminPutGameJSONBodyState.
-const (
- AdminPutGameJSONBodyStateClosed AdminPutGameJSONBodyState = "closed"
- AdminPutGameJSONBodyStateFinished AdminPutGameJSONBodyState = "finished"
- AdminPutGameJSONBodyStateGaming AdminPutGameJSONBodyState = "gaming"
- AdminPutGameJSONBodyStatePrepare AdminPutGameJSONBodyState = "prepare"
- AdminPutGameJSONBodyStateStarting AdminPutGameJSONBodyState = "starting"
- AdminPutGameJSONBodyStateWaitingEntries AdminPutGameJSONBodyState = "waiting_entries"
- AdminPutGameJSONBodyStateWaitingStart AdminPutGameJSONBodyState = "waiting_start"
-)
-
// Error defines model for Error.
type Error struct {
Message string `json:"message"`
@@ -241,38 +230,6 @@ type NotFound = Error
// Unauthorized defines model for Unauthorized.
type Unauthorized = Error
-// AdminGetGamesParams defines parameters for AdminGetGames.
-type AdminGetGamesParams struct {
- Authorization HeaderAuthorization `json:"Authorization"`
-}
-
-// AdminGetGameParams defines parameters for AdminGetGame.
-type AdminGetGameParams struct {
- Authorization HeaderAuthorization `json:"Authorization"`
-}
-
-// AdminPutGameJSONBody defines parameters for AdminPutGame.
-type AdminPutGameJSONBody struct {
- DisplayName *string `json:"display_name,omitempty"`
- DurationSeconds *int `json:"duration_seconds,omitempty"`
- ProblemID nullable.Nullable[int] `json:"problem_id,omitempty"`
- StartedAt nullable.Nullable[int] `json:"started_at,omitempty"`
- State *AdminPutGameJSONBodyState `json:"state,omitempty"`
-}
-
-// AdminPutGameParams defines parameters for AdminPutGame.
-type AdminPutGameParams struct {
- Authorization HeaderAuthorization `json:"Authorization"`
-}
-
-// AdminPutGameJSONBodyState defines parameters for AdminPutGame.
-type AdminPutGameJSONBodyState string
-
-// AdminGetUsersParams defines parameters for AdminGetUsers.
-type AdminGetUsersParams struct {
- Authorization HeaderAuthorization `json:"Authorization"`
-}
-
// GetGamesParams defines parameters for GetGames.
type GetGamesParams struct {
Authorization HeaderAuthorization `json:"Authorization"`
@@ -294,9 +251,6 @@ type GetTokenParams struct {
Authorization HeaderAuthorization `json:"Authorization"`
}
-// AdminPutGameJSONRequestBody defines body for AdminPutGame for application/json ContentType.
-type AdminPutGameJSONRequestBody AdminPutGameJSONBody
-
// PostLoginJSONRequestBody defines body for PostLogin for application/json ContentType.
type PostLoginJSONRequestBody PostLoginJSONBody
@@ -691,18 +645,6 @@ func (t *GameWatcherMessageS2C) UnmarshalJSON(b []byte) error {
// ServerInterface represents all server handlers.
type ServerInterface interface {
// List games
- // (GET /admin/games)
- AdminGetGames(ctx echo.Context, params AdminGetGamesParams) error
- // Get a game
- // (GET /admin/games/{game_id})
- AdminGetGame(ctx echo.Context, gameID PathGameID, params AdminGetGameParams) error
- // Update a game
- // (PUT /admin/games/{game_id})
- AdminPutGame(ctx echo.Context, gameID PathGameID, params AdminPutGameParams) error
- // List all users
- // (GET /admin/users)
- AdminGetUsers(ctx echo.Context, params AdminGetUsersParams) error
- // List games
// (GET /games)
GetGames(ctx echo.Context, params GetGamesParams) error
// Get a game
@@ -721,144 +663,6 @@ type ServerInterfaceWrapper struct {
Handler ServerInterface
}
-// AdminGetGames converts echo context to params.
-func (w *ServerInterfaceWrapper) AdminGetGames(ctx echo.Context) error {
- var err error
-
- // Parameter object where we will unmarshal all parameters from the context
- var params AdminGetGamesParams
-
- headers := ctx.Request().Header
- // ------------- Required header parameter "Authorization" -------------
- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found {
- var Authorization HeaderAuthorization
- n := len(valueList)
- if n != 1 {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n))
- }
-
- err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true})
- if err != nil {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err))
- }
-
- params.Authorization = Authorization
- } else {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found"))
- }
-
- // Invoke the callback with all the unmarshaled arguments
- err = w.Handler.AdminGetGames(ctx, params)
- return err
-}
-
-// AdminGetGame converts echo context to params.
-func (w *ServerInterfaceWrapper) AdminGetGame(ctx echo.Context) error {
- var err error
- // ------------- Path parameter "game_id" -------------
- 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 {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter game_id: %s", err))
- }
-
- // Parameter object where we will unmarshal all parameters from the context
- var params AdminGetGameParams
-
- headers := ctx.Request().Header
- // ------------- Required header parameter "Authorization" -------------
- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found {
- var Authorization HeaderAuthorization
- n := len(valueList)
- if n != 1 {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n))
- }
-
- err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true})
- if err != nil {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err))
- }
-
- params.Authorization = Authorization
- } else {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found"))
- }
-
- // Invoke the callback with all the unmarshaled arguments
- err = w.Handler.AdminGetGame(ctx, gameID, params)
- return err
-}
-
-// AdminPutGame converts echo context to params.
-func (w *ServerInterfaceWrapper) AdminPutGame(ctx echo.Context) error {
- var err error
- // ------------- Path parameter "game_id" -------------
- 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 {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter game_id: %s", err))
- }
-
- // Parameter object where we will unmarshal all parameters from the context
- var params AdminPutGameParams
-
- headers := ctx.Request().Header
- // ------------- Required header parameter "Authorization" -------------
- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found {
- var Authorization HeaderAuthorization
- n := len(valueList)
- if n != 1 {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n))
- }
-
- err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true})
- if err != nil {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err))
- }
-
- params.Authorization = Authorization
- } else {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found"))
- }
-
- // Invoke the callback with all the unmarshaled arguments
- err = w.Handler.AdminPutGame(ctx, gameID, params)
- return err
-}
-
-// AdminGetUsers converts echo context to params.
-func (w *ServerInterfaceWrapper) AdminGetUsers(ctx echo.Context) error {
- var err error
-
- // Parameter object where we will unmarshal all parameters from the context
- var params AdminGetUsersParams
-
- headers := ctx.Request().Header
- // ------------- Required header parameter "Authorization" -------------
- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found {
- var Authorization HeaderAuthorization
- n := len(valueList)
- if n != 1 {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n))
- }
-
- err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true})
- if err != nil {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err))
- }
-
- params.Authorization = Authorization
- } else {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found"))
- }
-
- // Invoke the callback with all the unmarshaled arguments
- err = w.Handler.AdminGetUsers(ctx, params)
- return err
-}
-
// GetGames converts echo context to params.
func (w *ServerInterfaceWrapper) GetGames(ctx echo.Context) error {
var err error
@@ -996,10 +800,6 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL
Handler: si,
}
- router.GET(baseURL+"/admin/games", wrapper.AdminGetGames)
- router.GET(baseURL+"/admin/games/:game_id", wrapper.AdminGetGame)
- router.PUT(baseURL+"/admin/games/:game_id", wrapper.AdminPutGame)
- router.GET(baseURL+"/admin/users", wrapper.AdminGetUsers)
router.GET(baseURL+"/games", wrapper.GetGames)
router.GET(baseURL+"/games/:game_id", wrapper.GetGame)
router.POST(baseURL+"/login", wrapper.PostLogin)
@@ -1015,181 +815,6 @@ type NotFoundJSONResponse Error
type UnauthorizedJSONResponse Error
-type AdminGetGamesRequestObject struct {
- Params AdminGetGamesParams
-}
-
-type AdminGetGamesResponseObject interface {
- VisitAdminGetGamesResponse(w http.ResponseWriter) error
-}
-
-type AdminGetGames200JSONResponse struct {
- Games []Game `json:"games"`
-}
-
-func (response AdminGetGames200JSONResponse) VisitAdminGetGamesResponse(w http.ResponseWriter) error {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(200)
-
- return json.NewEncoder(w).Encode(response)
-}
-
-type AdminGetGames401JSONResponse struct{ UnauthorizedJSONResponse }
-
-func (response AdminGetGames401JSONResponse) VisitAdminGetGamesResponse(w http.ResponseWriter) error {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(401)
-
- return json.NewEncoder(w).Encode(response)
-}
-
-type AdminGetGames403JSONResponse struct{ ForbiddenJSONResponse }
-
-func (response AdminGetGames403JSONResponse) VisitAdminGetGamesResponse(w http.ResponseWriter) error {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(403)
-
- return json.NewEncoder(w).Encode(response)
-}
-
-type AdminGetGameRequestObject struct {
- GameID PathGameID `json:"game_id"`
- Params AdminGetGameParams
-}
-
-type AdminGetGameResponseObject interface {
- VisitAdminGetGameResponse(w http.ResponseWriter) error
-}
-
-type AdminGetGame200JSONResponse struct {
- Game Game `json:"game"`
-}
-
-func (response AdminGetGame200JSONResponse) VisitAdminGetGameResponse(w http.ResponseWriter) error {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(200)
-
- return json.NewEncoder(w).Encode(response)
-}
-
-type AdminGetGame401JSONResponse struct{ UnauthorizedJSONResponse }
-
-func (response AdminGetGame401JSONResponse) VisitAdminGetGameResponse(w http.ResponseWriter) error {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(401)
-
- return json.NewEncoder(w).Encode(response)
-}
-
-type AdminGetGame403JSONResponse struct{ ForbiddenJSONResponse }
-
-func (response AdminGetGame403JSONResponse) VisitAdminGetGameResponse(w http.ResponseWriter) error {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(403)
-
- return json.NewEncoder(w).Encode(response)
-}
-
-type AdminGetGame404JSONResponse struct{ NotFoundJSONResponse }
-
-func (response AdminGetGame404JSONResponse) VisitAdminGetGameResponse(w http.ResponseWriter) error {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(404)
-
- return json.NewEncoder(w).Encode(response)
-}
-
-type AdminPutGameRequestObject struct {
- GameID PathGameID `json:"game_id"`
- Params AdminPutGameParams
- Body *AdminPutGameJSONRequestBody
-}
-
-type AdminPutGameResponseObject interface {
- VisitAdminPutGameResponse(w http.ResponseWriter) error
-}
-
-type AdminPutGame204Response struct {
-}
-
-func (response AdminPutGame204Response) VisitAdminPutGameResponse(w http.ResponseWriter) error {
- w.WriteHeader(204)
- return nil
-}
-
-type AdminPutGame400JSONResponse struct{ BadRequestJSONResponse }
-
-func (response AdminPutGame400JSONResponse) VisitAdminPutGameResponse(w http.ResponseWriter) error {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(400)
-
- return json.NewEncoder(w).Encode(response)
-}
-
-type AdminPutGame401JSONResponse struct{ UnauthorizedJSONResponse }
-
-func (response AdminPutGame401JSONResponse) VisitAdminPutGameResponse(w http.ResponseWriter) error {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(401)
-
- return json.NewEncoder(w).Encode(response)
-}
-
-type AdminPutGame403JSONResponse struct{ ForbiddenJSONResponse }
-
-func (response AdminPutGame403JSONResponse) VisitAdminPutGameResponse(w http.ResponseWriter) error {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(403)
-
- return json.NewEncoder(w).Encode(response)
-}
-
-type AdminPutGame404JSONResponse struct{ NotFoundJSONResponse }
-
-func (response AdminPutGame404JSONResponse) VisitAdminPutGameResponse(w http.ResponseWriter) error {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(404)
-
- return json.NewEncoder(w).Encode(response)
-}
-
-type AdminGetUsersRequestObject struct {
- Params AdminGetUsersParams
-}
-
-type AdminGetUsersResponseObject interface {
- VisitAdminGetUsersResponse(w http.ResponseWriter) error
-}
-
-type AdminGetUsers200JSONResponse struct {
- Users []User `json:"users"`
-}
-
-func (response AdminGetUsers200JSONResponse) VisitAdminGetUsersResponse(w http.ResponseWriter) error {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(200)
-
- return json.NewEncoder(w).Encode(response)
-}
-
-type AdminGetUsers401JSONResponse struct{ UnauthorizedJSONResponse }
-
-func (response AdminGetUsers401JSONResponse) VisitAdminGetUsersResponse(w http.ResponseWriter) error {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(401)
-
- return json.NewEncoder(w).Encode(response)
-}
-
-type AdminGetUsers403JSONResponse struct{ ForbiddenJSONResponse }
-
-func (response AdminGetUsers403JSONResponse) VisitAdminGetUsersResponse(w http.ResponseWriter) error {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(403)
-
- return json.NewEncoder(w).Encode(response)
-}
-
type GetGamesRequestObject struct {
Params GetGamesParams
}
@@ -1333,18 +958,6 @@ func (response GetToken401JSONResponse) VisitGetTokenResponse(w http.ResponseWri
// StrictServerInterface represents all server handlers.
type StrictServerInterface interface {
// List games
- // (GET /admin/games)
- AdminGetGames(ctx context.Context, request AdminGetGamesRequestObject) (AdminGetGamesResponseObject, error)
- // Get a game
- // (GET /admin/games/{game_id})
- AdminGetGame(ctx context.Context, request AdminGetGameRequestObject) (AdminGetGameResponseObject, error)
- // Update a game
- // (PUT /admin/games/{game_id})
- AdminPutGame(ctx context.Context, request AdminPutGameRequestObject) (AdminPutGameResponseObject, error)
- // List all users
- // (GET /admin/users)
- AdminGetUsers(ctx context.Context, request AdminGetUsersRequestObject) (AdminGetUsersResponseObject, error)
- // List games
// (GET /games)
GetGames(ctx context.Context, request GetGamesRequestObject) (GetGamesResponseObject, error)
// Get a game
@@ -1370,114 +983,6 @@ type strictHandler struct {
middlewares []StrictMiddlewareFunc
}
-// AdminGetGames operation middleware
-func (sh *strictHandler) AdminGetGames(ctx echo.Context, params AdminGetGamesParams) error {
- var request AdminGetGamesRequestObject
-
- request.Params = params
-
- handler := func(ctx echo.Context, request interface{}) (interface{}, error) {
- return sh.ssi.AdminGetGames(ctx.Request().Context(), request.(AdminGetGamesRequestObject))
- }
- for _, middleware := range sh.middlewares {
- handler = middleware(handler, "AdminGetGames")
- }
-
- response, err := handler(ctx, request)
-
- if err != nil {
- return err
- } else if validResponse, ok := response.(AdminGetGamesResponseObject); ok {
- return validResponse.VisitAdminGetGamesResponse(ctx.Response())
- } else if response != nil {
- return fmt.Errorf("unexpected response type: %T", response)
- }
- return nil
-}
-
-// AdminGetGame operation middleware
-func (sh *strictHandler) AdminGetGame(ctx echo.Context, gameID PathGameID, params AdminGetGameParams) error {
- var request AdminGetGameRequestObject
-
- request.GameID = gameID
- request.Params = params
-
- handler := func(ctx echo.Context, request interface{}) (interface{}, error) {
- return sh.ssi.AdminGetGame(ctx.Request().Context(), request.(AdminGetGameRequestObject))
- }
- for _, middleware := range sh.middlewares {
- handler = middleware(handler, "AdminGetGame")
- }
-
- response, err := handler(ctx, request)
-
- if err != nil {
- return err
- } else if validResponse, ok := response.(AdminGetGameResponseObject); ok {
- return validResponse.VisitAdminGetGameResponse(ctx.Response())
- } else if response != nil {
- return fmt.Errorf("unexpected response type: %T", response)
- }
- return nil
-}
-
-// AdminPutGame operation middleware
-func (sh *strictHandler) AdminPutGame(ctx echo.Context, gameID PathGameID, params AdminPutGameParams) error {
- var request AdminPutGameRequestObject
-
- request.GameID = gameID
- request.Params = params
-
- var body AdminPutGameJSONRequestBody
- if err := ctx.Bind(&body); err != nil {
- return err
- }
- request.Body = &body
-
- handler := func(ctx echo.Context, request interface{}) (interface{}, error) {
- return sh.ssi.AdminPutGame(ctx.Request().Context(), request.(AdminPutGameRequestObject))
- }
- for _, middleware := range sh.middlewares {
- handler = middleware(handler, "AdminPutGame")
- }
-
- response, err := handler(ctx, request)
-
- if err != nil {
- return err
- } else if validResponse, ok := response.(AdminPutGameResponseObject); ok {
- return validResponse.VisitAdminPutGameResponse(ctx.Response())
- } else if response != nil {
- return fmt.Errorf("unexpected response type: %T", response)
- }
- return nil
-}
-
-// AdminGetUsers operation middleware
-func (sh *strictHandler) AdminGetUsers(ctx echo.Context, params AdminGetUsersParams) error {
- var request AdminGetUsersRequestObject
-
- request.Params = params
-
- handler := func(ctx echo.Context, request interface{}) (interface{}, error) {
- return sh.ssi.AdminGetUsers(ctx.Request().Context(), request.(AdminGetUsersRequestObject))
- }
- for _, middleware := range sh.middlewares {
- handler = middleware(handler, "AdminGetUsers")
- }
-
- response, err := handler(ctx, request)
-
- if err != nil {
- return err
- } else if validResponse, ok := response.(AdminGetUsersResponseObject); ok {
- return validResponse.VisitAdminGetUsersResponse(ctx.Response())
- } else if response != nil {
- return fmt.Errorf("unexpected response type: %T", response)
- }
- return nil
-}
-
// GetGames operation middleware
func (sh *strictHandler) GetGames(ctx echo.Context, params GetGamesParams) error {
var request GetGamesRequestObject
@@ -1586,33 +1091,31 @@ func (sh *strictHandler) GetToken(ctx echo.Context, params GetTokenParams) error
// Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{
- "H4sIAAAAAAAC/+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swagger specification file
diff --git a/backend/api/handler_wrapper.go b/backend/api/handler_wrapper.go
index 939e37a..fdee581 100644
--- a/backend/api/handler_wrapper.go
+++ b/backend/api/handler_wrapper.go
@@ -39,82 +39,6 @@ func parseJWTClaimsFromAuthorizationHeader(authorization string) (*auth.JWTClaim
return claims, nil
}
-func (h *ApiHandlerWrapper) AdminGetGame(ctx context.Context, request AdminGetGameRequestObject) (AdminGetGameResponseObject, error) {
- user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization)
- if err != nil {
- return AdminGetGame401JSONResponse{
- UnauthorizedJSONResponse: UnauthorizedJSONResponse{
- Message: "Unauthorized",
- },
- }, nil
- }
- if !user.IsAdmin {
- return AdminGetGame403JSONResponse{
- ForbiddenJSONResponse: ForbiddenJSONResponse{
- Message: "Forbidden",
- },
- }, nil
- }
- return h.innerHandler.AdminGetGame(ctx, request, user)
-}
-
-func (h *ApiHandlerWrapper) AdminGetGames(ctx context.Context, request AdminGetGamesRequestObject) (AdminGetGamesResponseObject, error) {
- user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization)
- if err != nil {
- return AdminGetGames401JSONResponse{
- UnauthorizedJSONResponse: UnauthorizedJSONResponse{
- Message: "Unauthorized",
- },
- }, nil
- }
- if !user.IsAdmin {
- return AdminGetGames403JSONResponse{
- ForbiddenJSONResponse: ForbiddenJSONResponse{
- Message: "Forbidden",
- },
- }, nil
- }
- return h.innerHandler.AdminGetGames(ctx, request, user)
-}
-
-func (h *ApiHandlerWrapper) AdminGetUsers(ctx context.Context, request AdminGetUsersRequestObject) (AdminGetUsersResponseObject, error) {
- user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization)
- if err != nil {
- return AdminGetUsers401JSONResponse{
- UnauthorizedJSONResponse: UnauthorizedJSONResponse{
- Message: "Unauthorized",
- },
- }, nil
- }
- if !user.IsAdmin {
- return AdminGetUsers403JSONResponse{
- ForbiddenJSONResponse: ForbiddenJSONResponse{
- Message: "Forbidden",
- },
- }, nil
- }
- return h.innerHandler.AdminGetUsers(ctx, request, user)
-}
-
-func (h *ApiHandlerWrapper) AdminPutGame(ctx context.Context, request AdminPutGameRequestObject) (AdminPutGameResponseObject, error) {
- user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization)
- if err != nil {
- return AdminPutGame401JSONResponse{
- UnauthorizedJSONResponse: UnauthorizedJSONResponse{
- Message: "Unauthorized",
- },
- }, nil
- }
- if !user.IsAdmin {
- return AdminPutGame403JSONResponse{
- ForbiddenJSONResponse: ForbiddenJSONResponse{
- Message: "Forbidden",
- },
- }, nil
- }
- return h.innerHandler.AdminPutGame(ctx, request, user)
-}
-
func (h *ApiHandlerWrapper) GetGame(ctx context.Context, request GetGameRequestObject) (GetGameResponseObject, error) {
user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization)
if err != nil {
diff --git a/backend/api/handlers.go b/backend/api/handlers.go
index 8dfc11c..a824f17 100644
--- a/backend/api/handlers.go
+++ b/backend/api/handlers.go
@@ -4,10 +4,8 @@ import (
"context"
"errors"
"net/http"
- "time"
"github.com/jackc/pgx/v5"
- "github.com/jackc/pgx/v5/pgtype"
"github.com/labstack/echo/v4"
"github.com/nsfisis/iosdc-japan-2024-albatross/backend/auth"
@@ -23,191 +21,6 @@ type GameHubsInterface interface {
StartGame(gameID int) error
}
-func (h *ApiHandler) AdminGetGames(ctx context.Context, request AdminGetGamesRequestObject, user *auth.JWTClaims) (AdminGetGamesResponseObject, error) {
- 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
- }
- 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,
- }
- }
- return AdminGetGames200JSONResponse{
- Games: games,
- }, nil
-}
-
-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))
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return AdminGetGame404JSONResponse{
- NotFoundJSONResponse: NotFoundJSONResponse{
- Message: "Game not found",
- },
- }, nil
- } else {
- 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 != nil {
- if row.Title == nil || row.Description == nil {
- panic("inconsistent data")
- }
- problem = &Problem{
- ProblemID: int(*row.ProblemID),
- Title: *row.Title,
- Description: *row.Description,
- }
- }
- game := Game{
- GameID: int(row.GameID),
- State: GameState(row.State),
- DisplayName: row.DisplayName,
- DurationSeconds: int(row.DurationSeconds),
- StartedAt: startedAt,
- Problem: problem,
- }
- return AdminGetGame200JSONResponse{
- Game: game,
- }, nil
-}
-
-func (h *ApiHandler) AdminPutGame(ctx context.Context, request AdminPutGameRequestObject, user *auth.JWTClaims) (AdminPutGameResponseObject, error) {
- gameID := request.GameID
- displayName := request.Body.DisplayName
- durationSeconds := request.Body.DurationSeconds
- problemID := request.Body.ProblemID
- startedAt := request.Body.StartedAt
- state := request.Body.State
-
- game, err := h.q.GetGameByID(ctx, int32(gameID))
- if err != nil {
- if err == pgx.ErrNoRows {
- return AdminPutGame404JSONResponse{
- NotFoundJSONResponse: NotFoundJSONResponse{
- Message: "Game not found",
- },
- }, nil
- } else {
- return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error())
- }
- }
-
- var changedState string
- if state != nil {
- changedState = string(*state)
- // TODO:
- if changedState != game.State && changedState == "prepare" {
- h.hubs.StartGame(int(gameID))
- }
- } else {
- changedState = game.State
- }
- var changedDisplayName string
- if displayName != nil {
- changedDisplayName = *displayName
- } else {
- changedDisplayName = game.DisplayName
- }
- var changedDurationSeconds int32
- if durationSeconds != nil {
- changedDurationSeconds = int32(*durationSeconds)
- } else {
- changedDurationSeconds = game.DurationSeconds
- }
- var changedStartedAt pgtype.Timestamp
- if startedAt != nil {
- startedAtValue, err := startedAt.Get()
- if err == nil {
- changedStartedAt = pgtype.Timestamp{
- Time: time.Unix(int64(startedAtValue), 0),
- Valid: true,
- }
- }
- } else {
- changedStartedAt = game.StartedAt
- }
- var changedProblemID *int32
- if problemID != nil {
- problemIDValue, err := problemID.Get()
- if err == nil {
- changedProblemID = new(int32)
- *changedProblemID = int32(problemIDValue)
- }
- } else {
- changedProblemID = game.ProblemID
- }
-
- err = h.q.UpdateGame(ctx, db.UpdateGameParams{
- GameID: int32(gameID),
- State: changedState,
- DisplayName: changedDisplayName,
- DurationSeconds: changedDurationSeconds,
- StartedAt: changedStartedAt,
- ProblemID: changedProblemID,
- })
- if err != nil {
- return AdminPutGame400JSONResponse{
- BadRequestJSONResponse: BadRequestJSONResponse{
- Message: err.Error(),
- },
- }, nil
- }
-
- return AdminPutGame204Response{}, nil
-}
-
-func (h *ApiHandler) AdminGetUsers(ctx context.Context, request AdminGetUsersRequestObject, user *auth.JWTClaims) (AdminGetUsersResponseObject, error) {
- users, err := h.q.ListUsers(ctx)
- if err != nil {
- return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error())
- }
- responseUsers := make([]User, len(users))
- for i, u := range users {
- responseUsers[i] = User{
- UserID: int(u.UserID),
- Username: u.Username,
- DisplayName: u.DisplayName,
- IconPath: u.IconPath,
- IsAdmin: u.IsAdmin,
- }
- }
- return AdminGetUsers200JSONResponse{
- Users: responseUsers,
- }, nil
-}
-
func (h *ApiHandler) PostLogin(ctx context.Context, request PostLoginRequestObject) (PostLoginResponseObject, error) {
username := request.Body.Username
password := request.Body.Password
@@ -311,7 +124,7 @@ func (h *ApiHandler) GetGame(ctx context.Context, request GetGameRequestObject,
if row.Title == nil || row.Description == nil {
panic("inconsistent data")
}
- if user.IsAdmin || (GameState(row.State) != GameStateClosed && GameState(row.State) != GameStateWaitingEntries) {
+ if user.IsAdmin || (GameState(row.State) != Closed && GameState(row.State) != WaitingEntries) {
problem = &Problem{
ProblemID: int(*row.ProblemID),
Title: *row.Title,
diff --git a/backend/game/models.go b/backend/game/models.go
index 13e3d0f..6c299d6 100644
--- a/backend/game/models.go
+++ b/backend/game/models.go
@@ -9,13 +9,13 @@ import (
type gameState = api.GameState
const (
- gameStateClosed gameState = api.GameStateClosed
- gameStateWaitingEntries gameState = api.GameStateWaitingEntries
- gameStateWaitingStart gameState = api.GameStateWaitingStart
- gameStatePrepare gameState = api.GameStatePrepare
- gameStateStarting gameState = api.GameStateStarting
- gameStateGaming gameState = api.GameStateGaming
- gameStateFinished gameState = api.GameStateFinished
+ gameStateClosed gameState = api.Closed
+ gameStateWaitingEntries gameState = api.WaitingEntries
+ gameStateWaitingStart gameState = api.WaitingStart
+ gameStatePrepare gameState = api.Prepare
+ gameStateStarting gameState = api.Starting
+ gameStateGaming gameState = api.Gaming
+ gameStateFinished gameState = api.Finished
)
type game struct {