diff --git a/bin/evening_detective_server b/bin/evening_detective_server index 1c9bddf..e1b6b23 100755 Binary files a/bin/evening_detective_server and b/bin/evening_detective_server differ diff --git a/internal/repos/team.go b/internal/repos/team.go index ed00bdd..87cdb69 100644 --- a/internal/repos/team.go +++ b/internal/repos/team.go @@ -1,9 +1,9 @@ package repos type Team struct { - ID int - Name string - Status string - Password string - ScenarioId int + ID int + Name string + Status string + Password string + GameId int } diff --git a/internal/repos/teams_repo/repo.go b/internal/repos/teams_repo/repo.go index cd1b813..15186a2 100644 --- a/internal/repos/teams_repo/repo.go +++ b/internal/repos/teams_repo/repo.go @@ -32,7 +32,7 @@ func (r *TeamsRepo) GetTeamByID(ctx context.Context, id int) (*repos.Team, error name, status, password, - scenario_id + game_id FROM teams WHERE id = $1`, id, @@ -42,7 +42,7 @@ func (r *TeamsRepo) GetTeamByID(ctx context.Context, id int) (*repos.Team, error &team.Name, &team.Status, &team.Password, - &team.ScenarioId, + &team.GameId, ) if err != nil { if errors.Is(err, pgx.ErrNoRows) { @@ -101,19 +101,17 @@ func (r *TeamsRepo) AddTeam( creatorId int, gameId int, name string, - scenarioId int, password string, ) (int, error) { id := 0 err := r.pool.QueryRow( ctx, - `INSERT INTO teams (name, creator_id, game_id, scenario_id, password) - VALUES ($1, $2, $3, $4, $5) + `INSERT INTO teams (name, creator_id, game_id, password) + VALUES ($1, $2, $3, $4) RETURNING id`, name, creatorId, gameId, - scenarioId, password, ).Scan(&id) diff --git a/internal/services/game_service/service.go b/internal/services/game_service/service.go index 9b56d10..6df57d1 100644 --- a/internal/services/game_service/service.go +++ b/internal/services/game_service/service.go @@ -145,15 +145,11 @@ func (s *GameService) AddTeam( gameId int, name string, ) (*Team, error) { - game, err := s.gamesRepo.GetGameByID(ctx, gameId) - if err != nil { - return nil, err - } password, err := s.passwordGenerator.Generate() if err != nil { 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 { return nil, err } @@ -185,12 +181,17 @@ func (s *GameService) GetTeamActions(ctx context.Context, teamId int, password s 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) if err != nil { return nil, err } - scenario, err := s.scenarioService.GetFullScenarioByID(ctx, team.ScenarioId) + scenario, err := s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioId) if err != nil { return nil, err } @@ -213,12 +214,17 @@ func (s *GameService) AddTeamAction(ctx context.Context, teamId int, password st return err } + game, err := s.gamesRepo.GetGameByID(ctx, team.GameId) + if err != nil { + return err + } + actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId) if err != nil { return err } - scenario, err := s.scenarioService.GetFullScenarioByID(ctx, team.ScenarioId) + scenario, err := s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioId) if err != nil { return err } @@ -243,12 +249,17 @@ func (s *GameService) DeleteLastTeamAction(ctx context.Context, teamId int) erro return err } + game, err := s.gamesRepo.GetGameByID(ctx, team.GameId) + if err != nil { + return err + } + actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId) if err != nil { return err } - scenario, err := s.scenarioService.GetFullScenarioByID(ctx, team.ScenarioId) + scenario, err := s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioId) if err != nil { return err } diff --git a/migrations/20260725141619_crerate_teams_table.sql b/migrations/20260725141619_crerate_teams_table.sql index c441df6..90ed52b 100644 --- a/migrations/20260725141619_crerate_teams_table.sql +++ b/migrations/20260725141619_crerate_teams_table.sql @@ -6,13 +6,11 @@ CREATE TABLE status VARCHAR(50) DEFAULT 'register', creator_id INTEGER NOT NULL, game_id INTEGER NOT NULL, - scenario_id INTEGER NOT NULL, password TEXT, created_at TIMESTAMP NOT NULL DEFAULT NOW (), 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_scenario FOREIGN KEY (scenario_id) REFERENCES scenarios (id) ON DELETE RESTRICT + CONSTRAINT fk_teams_creator FOREIGN KEY (creator_id) REFERENCES users (id) ON DELETE RESTRICT ); -- +goose Down diff --git a/migrations/20260725145354_crerate_links_table.sql b/migrations/20260725145354_crerate_links_table.sql deleted file mode 100644 index 379918e..0000000 --- a/migrations/20260725145354_crerate_links_table.sql +++ /dev/null @@ -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;