aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-01 21:38:49 +0900
committernsfisis <nsfisis@gmail.com>2024-08-01 21:38:49 +0900
commit0de9bf8ddbc2128e472b6a40d92bffbbf829fe42 (patch)
tree89378dd546b033586b11ad198c29302221802463 /backend
parent922d9348cf59df248873e27af3b27dbb0d93d9b1 (diff)
downloadiosdc-japan-2025-albatross-0de9bf8ddbc2128e472b6a40d92bffbbf829fe42.tar.gz
iosdc-japan-2025-albatross-0de9bf8ddbc2128e472b6a40d92bffbbf829fe42.tar.zst
iosdc-japan-2025-albatross-0de9bf8ddbc2128e472b6a40d92bffbbf829fe42.zip
refactor(backend): `Id` to `ID` in oapi-codegen
Diffstat (limited to 'backend')
-rw-r--r--backend/api/generated.go58
-rw-r--r--backend/api/handlers.go26
-rw-r--r--backend/game/hub.go6
-rw-r--r--backend/gen/oapi-codegen.yaml1
4 files changed, 46 insertions, 45 deletions
diff --git a/backend/api/generated.go b/backend/api/generated.go
index a643833..bb9b624 100644
--- a/backend/api/generated.go
+++ b/backend/api/generated.go
@@ -63,7 +63,7 @@ type Error struct {
type Game struct {
DisplayName string `json:"display_name"`
DurationSeconds int `json:"duration_seconds"`
- GameId int `json:"game_id"`
+ GameID int `json:"game_id"`
Problem *Problem `json:"problem,omitempty"`
StartedAt *int `json:"started_at,omitempty"`
State GameState `json:"state"`
@@ -164,7 +164,7 @@ type GameWatcherMessageS2CCode struct {
// GameWatcherMessageS2CCodePayload defines model for GameWatcherMessageS2CCodePayload.
type GameWatcherMessageS2CCodePayload struct {
Code string `json:"code"`
- PlayerId int `json:"player_id"`
+ PlayerID int `json:"player_id"`
}
// GameWatcherMessageS2CExecResult defines model for GameWatcherMessageS2CExecResult.
@@ -175,7 +175,7 @@ type GameWatcherMessageS2CExecResult struct {
// GameWatcherMessageS2CExecResultPayload defines model for GameWatcherMessageS2CExecResultPayload.
type GameWatcherMessageS2CExecResultPayload struct {
- PlayerId int `json:"player_id"`
+ PlayerID int `json:"player_id"`
Score nullable.Nullable[int] `json:"score"`
Status GameWatcherMessageS2CExecResultPayloadStatus `json:"status"`
Stderr string `json:"stderr"`
@@ -199,7 +199,7 @@ type GameWatcherMessageS2CStartPayload struct {
// Problem defines model for Problem.
type Problem struct {
Description string `json:"description"`
- ProblemId int `json:"problem_id"`
+ ProblemID int `json:"problem_id"`
Title string `json:"title"`
}
@@ -208,15 +208,15 @@ type User struct {
DisplayName string `json:"display_name"`
IconPath *string `json:"icon_path,omitempty"`
IsAdmin bool `json:"is_admin"`
- UserId int `json:"user_id"`
+ UserID int `json:"user_id"`
Username string `json:"username"`
}
// HeaderAuthorization defines model for header_authorization.
type HeaderAuthorization = string
-// PathGameId defines model for path_game_id.
-type PathGameId = int
+// PathGameID defines model for path_game_id.
+type PathGameID = int
// BadRequest defines model for BadRequest.
type BadRequest = Error
@@ -244,7 +244,7 @@ type AdminGetGameParams struct {
type AdminPutGameJSONBody struct {
DisplayName *string `json:"display_name,omitempty"`
DurationSeconds *int `json:"duration_seconds,omitempty"`
- ProblemId nullable.Nullable[int] `json:"problem_id,omitempty"`
+ ProblemID nullable.Nullable[int] `json:"problem_id,omitempty"`
StartedAt nullable.Nullable[int] `json:"started_at,omitempty"`
State *AdminPutGameJSONBodyState `json:"state,omitempty"`
}
@@ -658,10 +658,10 @@ type ServerInterface interface {
AdminGetGames(ctx echo.Context, params AdminGetGamesParams) error
// Get a game
// (GET /admin/games/{game_id})
- AdminGetGame(ctx echo.Context, gameId PathGameId, 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 PathGameId, 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
@@ -670,7 +670,7 @@ type ServerInterface interface {
GetGames(ctx echo.Context, params GetGamesParams) error
// Get a game
// (GET /games/{game_id})
- GetGame(ctx echo.Context, gameId PathGameId, params GetGameParams) error
+ GetGame(ctx echo.Context, gameID PathGameID, params GetGameParams) error
// User login
// (POST /login)
PostLogin(ctx echo.Context) error
@@ -719,9 +719,9 @@ 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 PathGameId
+ var gameID PathGameID
- err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
+ 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))
}
@@ -749,7 +749,7 @@ func (w *ServerInterfaceWrapper) AdminGetGame(ctx echo.Context) error {
}
// Invoke the callback with all the unmarshaled arguments
- err = w.Handler.AdminGetGame(ctx, gameId, params)
+ err = w.Handler.AdminGetGame(ctx, gameID, params)
return err
}
@@ -757,9 +757,9 @@ 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 PathGameId
+ var gameID PathGameID
- err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
+ 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))
}
@@ -787,7 +787,7 @@ func (w *ServerInterfaceWrapper) AdminPutGame(ctx echo.Context) error {
}
// Invoke the callback with all the unmarshaled arguments
- err = w.Handler.AdminPutGame(ctx, gameId, params)
+ err = w.Handler.AdminPutGame(ctx, gameID, params)
return err
}
@@ -857,9 +857,9 @@ 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 PathGameId
+ var gameID PathGameID
- err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
+ 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))
}
@@ -887,7 +887,7 @@ func (w *ServerInterfaceWrapper) GetGame(ctx echo.Context) error {
}
// Invoke the callback with all the unmarshaled arguments
- err = w.Handler.GetGame(ctx, gameId, params)
+ err = w.Handler.GetGame(ctx, gameID, params)
return err
}
@@ -1016,7 +1016,7 @@ func (response AdminGetGames403JSONResponse) VisitAdminGetGamesResponse(w http.R
}
type AdminGetGameRequestObject struct {
- GameId PathGameId `json:"game_id"`
+ GameID PathGameID `json:"game_id"`
Params AdminGetGameParams
}
@@ -1063,7 +1063,7 @@ func (response AdminGetGame404JSONResponse) VisitAdminGetGameResponse(w http.Res
}
type AdminPutGameRequestObject struct {
- GameId PathGameId `json:"game_id"`
+ GameID PathGameID `json:"game_id"`
Params AdminPutGameParams
Body *AdminPutGameJSONRequestBody
}
@@ -1191,7 +1191,7 @@ func (response GetGames403JSONResponse) VisitGetGamesResponse(w http.ResponseWri
}
type GetGameRequestObject struct {
- GameId PathGameId `json:"game_id"`
+ GameID PathGameID `json:"game_id"`
Params GetGameParams
}
@@ -1359,10 +1359,10 @@ func (sh *strictHandler) AdminGetGames(ctx echo.Context, params AdminGetGamesPar
}
// AdminGetGame operation middleware
-func (sh *strictHandler) AdminGetGame(ctx echo.Context, gameId PathGameId, params AdminGetGameParams) error {
+func (sh *strictHandler) AdminGetGame(ctx echo.Context, gameID PathGameID, params AdminGetGameParams) error {
var request AdminGetGameRequestObject
- request.GameId = gameId
+ request.GameID = gameID
request.Params = params
handler := func(ctx echo.Context, request interface{}) (interface{}, error) {
@@ -1385,10 +1385,10 @@ func (sh *strictHandler) AdminGetGame(ctx echo.Context, gameId PathGameId, param
}
// AdminPutGame operation middleware
-func (sh *strictHandler) AdminPutGame(ctx echo.Context, gameId PathGameId, params AdminPutGameParams) error {
+func (sh *strictHandler) AdminPutGame(ctx echo.Context, gameID PathGameID, params AdminPutGameParams) error {
var request AdminPutGameRequestObject
- request.GameId = gameId
+ request.GameID = gameID
request.Params = params
var body AdminPutGameJSONRequestBody
@@ -1467,10 +1467,10 @@ func (sh *strictHandler) GetGames(ctx echo.Context, params GetGamesParams) error
}
// GetGame operation middleware
-func (sh *strictHandler) GetGame(ctx echo.Context, gameId PathGameId, params GetGameParams) error {
+func (sh *strictHandler) GetGame(ctx echo.Context, gameID PathGameID, params GetGameParams) error {
var request GetGameRequestObject
- request.GameId = gameId
+ request.GameID = gameID
request.Params = params
handler := func(ctx echo.Context, request interface{}) (interface{}, error) {
diff --git a/backend/api/handlers.go b/backend/api/handlers.go
index aba9366..8dfc11c 100644
--- a/backend/api/handlers.go
+++ b/backend/api/handlers.go
@@ -41,13 +41,13 @@ func (h *ApiHandler) AdminGetGames(ctx context.Context, request AdminGetGamesReq
panic("inconsistent data")
}
problem = &Problem{
- ProblemId: int(*row.ProblemID),
+ ProblemID: int(*row.ProblemID),
Title: *row.Title,
Description: *row.Description,
}
}
games[i] = Game{
- GameId: int(row.GameID),
+ GameID: int(row.GameID),
State: GameState(row.State),
DisplayName: row.DisplayName,
DurationSeconds: int(row.DurationSeconds),
@@ -61,7 +61,7 @@ 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
+ gameID := request.GameID
row, err := h.q.GetGameByID(ctx, int32(gameID))
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
@@ -85,13 +85,13 @@ func (h *ApiHandler) AdminGetGame(ctx context.Context, request AdminGetGameReque
panic("inconsistent data")
}
problem = &Problem{
- ProblemId: int(*row.ProblemID),
+ ProblemID: int(*row.ProblemID),
Title: *row.Title,
Description: *row.Description,
}
}
game := Game{
- GameId: int(row.GameID),
+ GameID: int(row.GameID),
State: GameState(row.State),
DisplayName: row.DisplayName,
DurationSeconds: int(row.DurationSeconds),
@@ -104,10 +104,10 @@ func (h *ApiHandler) AdminGetGame(ctx context.Context, request AdminGetGameReque
}
func (h *ApiHandler) AdminPutGame(ctx context.Context, request AdminPutGameRequestObject, user *auth.JWTClaims) (AdminPutGameResponseObject, error) {
- gameID := request.GameId
+ gameID := request.GameID
displayName := request.Body.DisplayName
durationSeconds := request.Body.DurationSeconds
- problemID := request.Body.ProblemId
+ problemID := request.Body.ProblemID
startedAt := request.Body.StartedAt
state := request.Body.State
@@ -196,7 +196,7 @@ func (h *ApiHandler) AdminGetUsers(ctx context.Context, request AdminGetUsersReq
responseUsers := make([]User, len(users))
for i, u := range users {
responseUsers[i] = User{
- UserId: int(u.UserID),
+ UserID: int(u.UserID),
Username: u.Username,
DisplayName: u.DisplayName,
IconPath: u.IconPath,
@@ -267,13 +267,13 @@ func (h *ApiHandler) GetGames(ctx context.Context, request GetGamesRequestObject
panic("inconsistent data")
}
problem = &Problem{
- ProblemId: int(*row.ProblemID),
+ ProblemID: int(*row.ProblemID),
Title: *row.Title,
Description: *row.Description,
}
}
games[i] = Game{
- GameId: int(row.GameID),
+ GameID: int(row.GameID),
State: GameState(row.State),
DisplayName: row.DisplayName,
DurationSeconds: int(row.DurationSeconds),
@@ -288,7 +288,7 @@ 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
+ gameID := request.GameID
row, err := h.q.GetGameByID(ctx, int32(gameID))
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
@@ -313,14 +313,14 @@ func (h *ApiHandler) GetGame(ctx context.Context, request GetGameRequestObject,
}
if user.IsAdmin || (GameState(row.State) != GameStateClosed && GameState(row.State) != GameStateWaitingEntries) {
problem = &Problem{
- ProblemId: int(*row.ProblemID),
+ ProblemID: int(*row.ProblemID),
Title: *row.Title,
Description: *row.Description,
}
}
}
game := Game{
- GameId: int(row.GameID),
+ GameID: int(row.GameID),
State: GameState(row.State),
DisplayName: row.DisplayName,
DurationSeconds: int(row.DurationSeconds),
diff --git a/backend/game/hub.go b/backend/game/hub.go
index e6981e8..c73009b 100644
--- a/backend/game/hub.go
+++ b/backend/game/hub.go
@@ -156,14 +156,14 @@ func (hub *gameHub) run() {
watcher.s2cMessages <- &watcherMessageS2CCode{
Type: watcherMessageTypeS2CCode,
Data: watcherMessageS2CCodePayload{
- PlayerId: message.client.playerID,
+ PlayerID: message.client.playerID,
Code: code,
},
}
watcher.s2cMessages <- &watcherMessageS2CExecResult{
Type: watcherMessageTypeS2CExecResult,
Data: watcherMessageS2CExecResultPayload{
- PlayerId: message.client.playerID,
+ PlayerID: message.client.playerID,
Score: nullable.NewNullableWithValue(score),
Stdout: "",
Stderr: "",
@@ -209,7 +209,7 @@ func (hub *gameHub) startGame() error {
Type: playerMessageTypeS2CPrepare,
Data: playerMessageS2CPreparePayload{
Problem: api.Problem{
- ProblemId: 1,
+ ProblemID: 1,
Title: "the answer",
Description: "print 42",
},
diff --git a/backend/gen/oapi-codegen.yaml b/backend/gen/oapi-codegen.yaml
index d235096..a581c6c 100644
--- a/backend/gen/oapi-codegen.yaml
+++ b/backend/gen/oapi-codegen.yaml
@@ -8,3 +8,4 @@ output: ../api/generated.go
output-options:
skip-prune: true
nullable-type: true
+ name-normalizer: ToCamelCaseWithInitialisms