diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-01 21:36:47 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-01 21:37:42 +0900 |
| commit | 922d9348cf59df248873e27af3b27dbb0d93d9b1 (patch) | |
| tree | c0ec259659fc0244c22750a7e18451efbe13446d | |
| parent | f6443042fbec1bd394439904f3c69e23709f7e6a (diff) | |
| download | phperkaigi-2025-albatross-922d9348cf59df248873e27af3b27dbb0d93d9b1.tar.gz phperkaigi-2025-albatross-922d9348cf59df248873e27af3b27dbb0d93d9b1.tar.zst phperkaigi-2025-albatross-922d9348cf59df248873e27af3b27dbb0d93d9b1.zip | |
refactor(backend): `Id` to `ID` in sqlc
| -rw-r--r-- | backend/api/handlers.go | 8 | ||||
| -rw-r--r-- | backend/db/query.sql.go | 16 | ||||
| -rw-r--r-- | backend/query.sql | 4 |
3 files changed, 14 insertions, 14 deletions
diff --git a/backend/api/handlers.go b/backend/api/handlers.go index 35fc9f7..aba9366 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -62,7 +62,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 - row, err := h.q.GetGameById(ctx, int32(gameID)) + row, err := h.q.GetGameByID(ctx, int32(gameID)) if err != nil { if errors.Is(err, pgx.ErrNoRows) { return AdminGetGame404JSONResponse{ @@ -111,7 +111,7 @@ func (h *ApiHandler) AdminPutGame(ctx context.Context, request AdminPutGameReque 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{ @@ -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{ @@ -289,7 +289,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 - row, err := h.q.GetGameById(ctx, int32(gameID)) + row, err := h.q.GetGameByID(ctx, int32(gameID)) if err != nil { if errors.Is(err, pgx.ErrNoRows) { return GetGame404JSONResponse{ 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/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 |
