diff options
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/db/models.go | 1 | ||||
| -rw-r--r-- | backend/db/query.sql.go | 12 | ||||
| -rw-r--r-- | backend/fixtures/dev.sql | 24 | ||||
| -rw-r--r-- | backend/schema.sql | 1 |
4 files changed, 29 insertions, 9 deletions
diff --git a/backend/db/models.go b/backend/db/models.go index 5ad4b6b..51157bc 100644 --- a/backend/db/models.go +++ b/backend/db/models.go @@ -10,6 +10,7 @@ import ( type Game struct { GameID int32 + GameType string State string DisplayName string DurationSeconds int32 diff --git a/backend/db/query.sql.go b/backend/db/query.sql.go index 074e767..464d7f8 100644 --- a/backend/db/query.sql.go +++ b/backend/db/query.sql.go @@ -12,7 +12,7 @@ import ( ) 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 +SELECT game_id, game_type, 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 @@ -20,6 +20,7 @@ LIMIT 1 type GetGameByIDRow struct { GameID int32 + GameType string State string DisplayName string DurationSeconds int32 @@ -36,6 +37,7 @@ func (q *Queries) GetGameByID(ctx context.Context, gameID int32) (GetGameByIDRow var i GetGameByIDRow err := row.Scan( &i.GameID, + &i.GameType, &i.State, &i.DisplayName, &i.DurationSeconds, @@ -108,12 +110,13 @@ func (q *Queries) GetUserByID(ctx context.Context, userID int32) (User, error) { } const listGames = `-- name: ListGames :many -SELECT game_id, state, display_name, duration_seconds, created_at, started_at, games.problem_id, problems.problem_id, title, description FROM games +SELECT game_id, game_type, 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 ` type ListGamesRow struct { GameID int32 + GameType string State string DisplayName string DurationSeconds int32 @@ -136,6 +139,7 @@ func (q *Queries) ListGames(ctx context.Context) ([]ListGamesRow, error) { var i ListGamesRow if err := rows.Scan( &i.GameID, + &i.GameType, &i.State, &i.DisplayName, &i.DurationSeconds, @@ -157,7 +161,7 @@ func (q *Queries) ListGames(ctx context.Context) ([]ListGamesRow, error) { } const listGamesForPlayer = `-- name: ListGamesForPlayer :many -SELECT games.game_id, state, display_name, duration_seconds, created_at, started_at, games.problem_id, problems.problem_id, title, description, game_players.game_id, user_id FROM games +SELECT games.game_id, game_type, state, display_name, duration_seconds, created_at, started_at, games.problem_id, problems.problem_id, title, description, game_players.game_id, user_id FROM games LEFT JOIN problems ON games.problem_id = problems.problem_id JOIN game_players ON games.game_id = game_players.game_id WHERE game_players.user_id = $1 @@ -165,6 +169,7 @@ WHERE game_players.user_id = $1 type ListGamesForPlayerRow struct { GameID int32 + GameType string State string DisplayName string DurationSeconds int32 @@ -189,6 +194,7 @@ func (q *Queries) ListGamesForPlayer(ctx context.Context, userID int32) ([]ListG var i ListGamesForPlayerRow if err := rows.Scan( &i.GameID, + &i.GameType, &i.State, &i.DisplayName, &i.DurationSeconds, diff --git a/backend/fixtures/dev.sql b/backend/fixtures/dev.sql index 5e47386..a468d01 100644 --- a/backend/fixtures/dev.sql +++ b/backend/fixtures/dev.sql @@ -17,14 +17,20 @@ INSERT INTO problems VALUES ('TEST problem 1', 'This is TEST problem 1'), ('TEST problem 2', 'This is TEST problem 2'), - ('TEST problem 3', 'This is TEST problem 3'); + ('TEST problem 3', 'This is TEST problem 3'), + ('TEST problem 4', 'This is TEST problem 4'), + ('TEST problem 5', 'This is TEST problem 5'), + ('TEST problem 6', 'This is TEST problem 6'); INSERT INTO games -(state, display_name, duration_seconds, problem_id) +(game_type, state, display_name, duration_seconds, problem_id) VALUES - ('waiting_entries', 'TEST game 1', 180, 1), - ('closed', 'TEST game 2', 180, 2), - ('finished', 'TEST game 3', 180, 3); + ('1v1', 'waiting_entries', 'TEST game 1', 180, 1), + ('1v1', 'closed', 'TEST game 2', 180, 2), + ('1v1', 'finished', 'TEST game 3', 180, 3), + ('multiplayer', 'waiting_start', 'TEST game 4', 180, 4), + ('multiplayer', 'closed', 'TEST game 5', 180, 5), + ('multiplayer', 'finished', 'TEST game 6', 180, 6); INSERT INTO game_players (game_id, user_id) @@ -34,4 +40,10 @@ VALUES (2, 1), (2, 2), (3, 1), - (3, 2); + (3, 2), + (4, 1), + (4, 2), + (5, 1), + (5, 2), + (6, 1), + (6, 2); diff --git a/backend/schema.sql b/backend/schema.sql index 4c63511..4a1d4b0 100644 --- a/backend/schema.sql +++ b/backend/schema.sql @@ -25,6 +25,7 @@ CREATE TABLE problems ( CREATE TABLE games ( game_id SERIAL PRIMARY KEY, + game_type VARCHAR(16) NOT NULL, state VARCHAR(32) NOT NULL, display_name VARCHAR(255) NOT NULL, duration_seconds INT NOT NULL, |
