generated from VLADIMIR/template
clear
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user