aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/api/generated.go58
-rw-r--r--backend/api/handlers.go34
-rw-r--r--backend/db/query.sql.go16
-rw-r--r--backend/game/http.go4
-rw-r--r--backend/game/hub.go6
-rw-r--r--backend/gen/oapi-codegen.yaml1
-rw-r--r--backend/main.go4
-rw-r--r--backend/query.sql4
8 files changed, 64 insertions, 63 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 35fc9f7..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,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{
@@ -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,14 +104,14 @@ 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
- game, err := h.q.GetGameById(ctx, int32(gameID))
+ game, err := h.q.GetGameByID(ctx, int32(gameID))
if err != nil {
if err == pgx.ErrNoRows {
return AdminPutGame404JSONResponse{
@@ -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,
@@ -220,7 +220,7 @@ func (h *ApiHandler) PostLogin(ctx context.Context, request PostLoginRequestObje
}, nil
}
- user, err := h.q.GetUserById(ctx, int32(userID))
+ user, err := h.q.GetUserByID(ctx, int32(userID))
if err != nil {
return PostLogin401JSONResponse{
UnauthorizedJSONResponse: UnauthorizedJSONResponse{
@@ -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,8 +288,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{
@@ -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/db/query.sql.go b/backend/db/query.sql.go
index b5fef29..074e767 100644
--- a/backend/db/query.sql.go
+++ b/backend/db/query.sql.go
@@ -11,14 +11,14 @@ import (
"github.com/jackc/pgx/v5/pgtype"
)
-const getGameById = `-- name: GetGameById :one
+const getGameByID = `-- name: GetGameByID :one
SELECT game_id, state, display_name, duration_seconds, created_at, started_at, games.problem_id, problems.problem_id, title, description FROM games
LEFT JOIN problems ON games.problem_id = problems.problem_id
WHERE games.game_id = $1
LIMIT 1
`
-type GetGameByIdRow struct {
+type GetGameByIDRow struct {
GameID int32
State string
DisplayName string
@@ -31,9 +31,9 @@ type GetGameByIdRow struct {
Description *string
}
-func (q *Queries) GetGameById(ctx context.Context, gameID int32) (GetGameByIdRow, error) {
- row := q.db.QueryRow(ctx, getGameById, gameID)
- var i GetGameByIdRow
+func (q *Queries) GetGameByID(ctx context.Context, gameID int32) (GetGameByIDRow, error) {
+ row := q.db.QueryRow(ctx, getGameByID, gameID)
+ var i GetGameByIDRow
err := row.Scan(
&i.GameID,
&i.State,
@@ -87,14 +87,14 @@ func (q *Queries) GetUserAuthByUsername(ctx context.Context, username string) (G
return i, err
}
-const getUserById = `-- name: GetUserById :one
+const getUserByID = `-- name: GetUserByID :one
SELECT user_id, username, display_name, icon_path, is_admin, created_at FROM users
WHERE users.user_id = $1
LIMIT 1
`
-func (q *Queries) GetUserById(ctx context.Context, userID int32) (User, error) {
- row := q.db.QueryRow(ctx, getUserById, userID)
+func (q *Queries) GetUserByID(ctx context.Context, userID int32) (User, error) {
+ row := q.db.QueryRow(ctx, getUserByID, userID)
var i User
err := row.Scan(
&i.UserID,
diff --git a/backend/game/http.go b/backend/game/http.go
index 18f6cda..f9036c5 100644
--- a/backend/game/http.go
+++ b/backend/game/http.go
@@ -27,7 +27,7 @@ func (h *sockHandler) HandleSockGolfPlay(c echo.Context) error {
}
// TODO: check user permission
- gameID, err := strconv.Atoi(c.Param("gameId"))
+ gameID, err := strconv.Atoi(c.Param("gameID"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid game id")
}
@@ -48,7 +48,7 @@ func (h *sockHandler) HandleSockGolfWatch(c echo.Context) error {
return echo.NewHTTPError(http.StatusForbidden, "Permission denied")
}
- gameID, err := strconv.Atoi(c.Param("gameId"))
+ gameID, err := strconv.Atoi(c.Param("gameID"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid game id")
}
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
diff --git a/backend/main.go b/backend/main.go
index 0257113..939df03 100644
--- a/backend/main.go
+++ b/backend/main.go
@@ -65,10 +65,10 @@ func main() {
defer gameHubs.Close()
sockGroup := e.Group("/sock")
sockHandler := gameHubs.SockHandler()
- sockGroup.GET("/golf/:gameId/play", func(c echo.Context) error {
+ sockGroup.GET("/golf/:gameID/play", func(c echo.Context) error {
return sockHandler.HandleSockGolfPlay(c)
})
- sockGroup.GET("/golf/:gameId/watch", func(c echo.Context) error {
+ sockGroup.GET("/golf/:gameID/watch", func(c echo.Context) error {
return sockHandler.HandleSockGolfWatch(c)
})
diff --git a/backend/query.sql b/backend/query.sql
index ed8c7bc..886f96c 100644
--- a/backend/query.sql
+++ b/backend/query.sql
@@ -1,4 +1,4 @@
--- name: GetUserById :one
+-- name: GetUserByID :one
SELECT * FROM users
WHERE users.user_id = $1
LIMIT 1;
@@ -32,7 +32,7 @@ UPDATE games
SET started_at = $2
WHERE game_id = $1;
--- name: GetGameById :one
+-- name: GetGameByID :one
SELECT * FROM games
LEFT JOIN problems ON games.problem_id = problems.problem_id
WHERE games.game_id = $1