generated from VLADIMIR/template
add teams operations
This commit is contained in:
@@ -2,6 +2,7 @@ package game_service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"evening_detective_server/internal/modules/password_generator"
|
||||
"evening_detective_server/internal/repos/games_repo"
|
||||
"evening_detective_server/internal/repos/scenarios_repo"
|
||||
"evening_detective_server/internal/repos/teams_repo"
|
||||
@@ -9,10 +10,11 @@ import (
|
||||
)
|
||||
|
||||
type GameService struct {
|
||||
gamesRepo *games_repo.GamesRepo
|
||||
teamsRepo *teams_repo.TeamsRepo
|
||||
scenariosRepo *scenarios_repo.ScenariosRepo
|
||||
domain string
|
||||
gamesRepo *games_repo.GamesRepo
|
||||
teamsRepo *teams_repo.TeamsRepo
|
||||
scenariosRepo *scenarios_repo.ScenariosRepo
|
||||
domain string
|
||||
passwordGenerator password_generator.IPasswordGenerator
|
||||
}
|
||||
|
||||
func NewGameService(
|
||||
@@ -20,12 +22,14 @@ func NewGameService(
|
||||
teamsRepo *teams_repo.TeamsRepo,
|
||||
scenariosRepo *scenarios_repo.ScenariosRepo,
|
||||
domain string,
|
||||
passwordGenerator password_generator.IPasswordGenerator,
|
||||
) *GameService {
|
||||
return &GameService{
|
||||
gamesRepo: gamesRepo,
|
||||
teamsRepo: teamsRepo,
|
||||
scenariosRepo: scenariosRepo,
|
||||
domain: domain,
|
||||
gamesRepo: gamesRepo,
|
||||
teamsRepo: teamsRepo,
|
||||
scenariosRepo: scenariosRepo,
|
||||
domain: domain,
|
||||
passwordGenerator: passwordGenerator,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,3 +95,29 @@ func (s *GameService) UpdateGame(
|
||||
) error {
|
||||
return s.gamesRepo.UpdateGame(ctx, id, name, description, startAt, scenarioId)
|
||||
}
|
||||
|
||||
func (s *GameService) AddTeam(
|
||||
ctx context.Context,
|
||||
creatorId int,
|
||||
gameId int,
|
||||
name string,
|
||||
) error {
|
||||
game, err := s.gamesRepo.GetGameByID(ctx, gameId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
password, err := s.passwordGenerator.Generate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = s.teamsRepo.AddTeam(ctx, creatorId, gameId, name, game.ScenarioId, password)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *GameService) UpdateTeam(ctx context.Context, teamId int, name string) error {
|
||||
return s.teamsRepo.UpdateTeam(ctx, teamId, name)
|
||||
}
|
||||
|
||||
func (s *GameService) DeleteTeam(ctx context.Context, teamId int) error {
|
||||
return s.teamsRepo.DeleteTeam(ctx, teamId)
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@ package game_service
|
||||
type Team struct {
|
||||
ID int
|
||||
Name string
|
||||
Status string
|
||||
Password string
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ func mapTeam(
|
||||
return &Team{
|
||||
ID: o.ID,
|
||||
Name: o.Name,
|
||||
Status: o.Status,
|
||||
Password: o.Password,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user