add teams operations

This commit is contained in:
2026-07-28 00:51:25 +07:00
parent 5a5b36e44d
commit f6934e9d5b
11 changed files with 199 additions and 35 deletions
+38 -8
View File
@@ -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)
}