generated from VLADIMIR/template
up
This commit is contained in:
+15
-13
@@ -6,17 +6,19 @@ import (
|
||||
|
||||
// Game describes a game and its scenario and teams.
|
||||
type Game struct {
|
||||
Export *GameExport
|
||||
Format string
|
||||
ID int
|
||||
Name string
|
||||
Description string
|
||||
Location *string
|
||||
StartAt time.Time
|
||||
Status string
|
||||
ScenarioID int
|
||||
Scenario *Scenario
|
||||
Teams []*Team
|
||||
StartedAt *time.Time
|
||||
EndedAt *time.Time
|
||||
Export *GameExport
|
||||
Format string
|
||||
ID int
|
||||
Name string
|
||||
WiFiName string
|
||||
WiFiPassword string
|
||||
Description string
|
||||
Location *string
|
||||
StartAt time.Time
|
||||
Status string
|
||||
ScenarioID int
|
||||
Scenario *Scenario
|
||||
Teams []*Team
|
||||
StartedAt *time.Time
|
||||
EndedAt *time.Time
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ func captureSnapshot(ctx context.Context, tx pgx.Tx, gameID int) ([]byte, error)
|
||||
`SELECT jsonb_build_object(
|
||||
'game', jsonb_build_object(
|
||||
'id', g.id, 'name', g.name, 'description', COALESCE(g.description, ''),
|
||||
'wifi_name', g.wifi_name, 'wifi_password', g.wifi_password,
|
||||
'location', g.location, 'start_at', g.start_at AT TIME ZONE 'UTC',
|
||||
'status', g.status, 'format', g.format, 'scenario_id', g.scenario_id,
|
||||
'playlist_id', COALESCE(m.playlist_id, g.playlist_id),
|
||||
|
||||
@@ -89,7 +89,7 @@ func (r *GameImportsRepo) Complete(ctx context.Context, id string, data []byte)
|
||||
_, err = tx.Exec(
|
||||
ctx,
|
||||
`INSERT INTO games (
|
||||
id, name, description, location, start_at, status, format, scenario_id, playlist_id
|
||||
id, name, description, location, start_at, status, format, scenario_id, playlist_id, wifi_name, wifi_password
|
||||
)
|
||||
SELECT
|
||||
g.id,
|
||||
@@ -100,10 +100,12 @@ func (r *GameImportsRepo) Complete(ctx context.Context, id string, data []byte)
|
||||
g.status,
|
||||
g.format,
|
||||
$2,
|
||||
($3::jsonb->>g.playlist_id::text)::integer
|
||||
($3::jsonb->>g.playlist_id::text)::integer,
|
||||
COALESCE(g.wifi_name, ''),
|
||||
COALESCE(g.wifi_password, '')
|
||||
FROM jsonb_to_record($1::jsonb->'game') AS g(
|
||||
id integer, name text, description text, location text, start_at timestamptz,
|
||||
status text, format text, playlist_id integer
|
||||
status text, format text, playlist_id integer, wifi_name text, wifi_password text
|
||||
)`,
|
||||
data,
|
||||
mappings.ScenarioID,
|
||||
|
||||
@@ -77,6 +77,8 @@ func (r *GamesRepo) GetGameByID(
|
||||
games.scenario_id,
|
||||
games.started_at,
|
||||
games.ended_at,
|
||||
games.wifi_name,
|
||||
games.wifi_password,
|
||||
(SELECT
|
||||
CASE WHEN e.released_at IS NOT NULL OR EXISTS (
|
||||
SELECT 1
|
||||
@@ -105,6 +107,8 @@ func (r *GamesRepo) GetGameByID(
|
||||
&game.ScenarioID,
|
||||
&game.StartedAt,
|
||||
&game.EndedAt,
|
||||
&game.WiFiName,
|
||||
&game.WiFiPassword,
|
||||
&game.Export,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -207,6 +211,7 @@ func (r *GamesRepo) UpdateGame(
|
||||
startAt time.Time,
|
||||
scenarioID int32,
|
||||
format string,
|
||||
wifiName, wifiPassword *string,
|
||||
) error {
|
||||
tag, err := r.pool.Exec(
|
||||
ctx,
|
||||
@@ -218,6 +223,8 @@ func (r *GamesRepo) UpdateGame(
|
||||
start_at = $4,
|
||||
scenario_id = $5,
|
||||
format = $6,
|
||||
wifi_name = COALESCE($8, wifi_name),
|
||||
wifi_password = COALESCE($9, wifi_password),
|
||||
updated_at = NOW()
|
||||
WHERE id = $7`,
|
||||
name,
|
||||
@@ -227,6 +234,8 @@ func (r *GamesRepo) UpdateGame(
|
||||
scenarioID,
|
||||
format,
|
||||
id,
|
||||
wifiName,
|
||||
wifiPassword,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user