This commit is contained in:
2026-08-03 00:49:27 +07:00
parent c32a11d124
commit 051b3e8bee
6 changed files with 29 additions and 36 deletions
Binary file not shown.
+1 -1
View File
@@ -5,5 +5,5 @@ type Team struct {
Name string Name string
Status string Status string
Password string Password string
ScenarioId int GameId int
} }
+4 -6
View File
@@ -32,7 +32,7 @@ func (r *TeamsRepo) GetTeamByID(ctx context.Context, id int) (*repos.Team, error
name, name,
status, status,
password, password,
scenario_id game_id
FROM teams FROM teams
WHERE id = $1`, WHERE id = $1`,
id, id,
@@ -42,7 +42,7 @@ func (r *TeamsRepo) GetTeamByID(ctx context.Context, id int) (*repos.Team, error
&team.Name, &team.Name,
&team.Status, &team.Status,
&team.Password, &team.Password,
&team.ScenarioId, &team.GameId,
) )
if err != nil { if err != nil {
if errors.Is(err, pgx.ErrNoRows) { if errors.Is(err, pgx.ErrNoRows) {
@@ -101,19 +101,17 @@ func (r *TeamsRepo) AddTeam(
creatorId int, creatorId int,
gameId int, gameId int,
name string, name string,
scenarioId int,
password string, password string,
) (int, error) { ) (int, error) {
id := 0 id := 0
err := r.pool.QueryRow( err := r.pool.QueryRow(
ctx, ctx,
`INSERT INTO teams (name, creator_id, game_id, scenario_id, password) `INSERT INTO teams (name, creator_id, game_id, password)
VALUES ($1, $2, $3, $4, $5) VALUES ($1, $2, $3, $4)
RETURNING id`, RETURNING id`,
name, name,
creatorId, creatorId,
gameId, gameId,
scenarioId,
password, password,
).Scan(&id) ).Scan(&id)
+19 -8
View File
@@ -145,15 +145,11 @@ func (s *GameService) AddTeam(
gameId int, gameId int,
name string, name string,
) (*Team, error) { ) (*Team, error) {
game, err := s.gamesRepo.GetGameByID(ctx, gameId)
if err != nil {
return nil, err
}
password, err := s.passwordGenerator.Generate() password, err := s.passwordGenerator.Generate()
if err != nil { if err != nil {
return nil, err return nil, err
} }
id, err := s.teamsRepo.AddTeam(ctx, creatorId, gameId, name, game.ScenarioId, password) id, err := s.teamsRepo.AddTeam(ctx, creatorId, gameId, name, password)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -185,12 +181,17 @@ func (s *GameService) GetTeamActions(ctx context.Context, teamId int, password s
return nil, teams_repo.ErrTeamNotFound return nil, teams_repo.ErrTeamNotFound
} }
game, err := s.gamesRepo.GetGameByID(ctx, team.GameId)
if err != nil {
return nil, err
}
actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId) actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, team.ScenarioId) scenario, err := s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -213,12 +214,17 @@ func (s *GameService) AddTeamAction(ctx context.Context, teamId int, password st
return err return err
} }
game, err := s.gamesRepo.GetGameByID(ctx, team.GameId)
if err != nil {
return err
}
actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId) actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
if err != nil { if err != nil {
return err return err
} }
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, team.ScenarioId) scenario, err := s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioId)
if err != nil { if err != nil {
return err return err
} }
@@ -243,12 +249,17 @@ func (s *GameService) DeleteLastTeamAction(ctx context.Context, teamId int) erro
return err return err
} }
game, err := s.gamesRepo.GetGameByID(ctx, team.GameId)
if err != nil {
return err
}
actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId) actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
if err != nil { if err != nil {
return err return err
} }
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, team.ScenarioId) scenario, err := s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioId)
if err != nil { if err != nil {
return err return err
} }
@@ -6,13 +6,11 @@ CREATE TABLE
status VARCHAR(50) DEFAULT 'register', status VARCHAR(50) DEFAULT 'register',
creator_id INTEGER NOT NULL, creator_id INTEGER NOT NULL,
game_id INTEGER NOT NULL, game_id INTEGER NOT NULL,
scenario_id INTEGER NOT NULL,
password TEXT, password TEXT,
created_at TIMESTAMP NOT NULL DEFAULT NOW (), created_at TIMESTAMP NOT NULL DEFAULT NOW (),
CONSTRAINT fk_teams_game FOREIGN KEY (game_id) REFERENCES games (id) ON DELETE RESTRICT, CONSTRAINT fk_teams_game FOREIGN KEY (game_id) REFERENCES games (id) ON DELETE RESTRICT,
CONSTRAINT fk_teams_creator FOREIGN KEY (creator_id) REFERENCES users (id) ON DELETE RESTRICT, CONSTRAINT fk_teams_creator FOREIGN KEY (creator_id) REFERENCES users (id) ON DELETE RESTRICT
CONSTRAINT fk_teams_scenario FOREIGN KEY (scenario_id) REFERENCES scenarios (id) ON DELETE RESTRICT
); );
-- +goose Down -- +goose Down
@@ -1,14 +0,0 @@
-- +goose Up
CREATE TABLE
IF NOT EXISTS links (
id SERIAL PRIMARY KEY,
team_id INTEGER,
game_id INTEGER,
created_at TIMESTAMP NOT NULL DEFAULT NOW (),
CONSTRAINT fk_links_team FOREIGN KEY (team_id) REFERENCES teams (id) ON DELETE RESTRICT,
CONSTRAINT fk_links_game FOREIGN KEY (game_id) REFERENCES games (id) ON DELETE RESTRICT
);
-- +goose Down
DROP TABLE IF EXISTS links;