diff --git a/bin/evening_detective_server b/bin/evening_detective_server index af9943f..2846676 100755 Binary files a/bin/evening_detective_server and b/bin/evening_detective_server differ diff --git a/docs/PARTICIPATION.md b/docs/PARTICIPATION.md index 132e7cb..f5305fc 100644 --- a/docs/PARTICIPATION.md +++ b/docs/PARTICIPATION.md @@ -8,7 +8,7 @@ ## Правила - `pending` — ожидает ответа; команда сохраняет право участвовать. -- `confirmed` — подтверждено капитаном или автоматически при регистрации менее чем за сутки. +- `confirmed` — подтверждено капитаном, первым ходом команды (`first_action`) или автоматически при регистрации менее чем за сутки. - `cancelled` — отменено; команда остаётся в истории организатора, но исключается из игры, ответов организатору, результатов, карты и PDF с QR-кодами. - Ровно за 24 часа автоматического подтверждения нет. diff --git a/internal/repos/teams_repo/participation.go b/internal/repos/teams_repo/participation.go index fe3fe1b..6d78a1b 100644 --- a/internal/repos/teams_repo/participation.go +++ b/internal/repos/teams_repo/participation.go @@ -117,6 +117,13 @@ func (r *TeamsRepo) SetParticipationToken(ctx context.Context, id int, token str return err } +func (r *TeamsRepo) ConfirmParticipationByFirstAction(ctx context.Context, teamID int) error { + _, err := r.pool.Exec(ctx, `UPDATE teams SET participation_status='confirmed', + participation_source='first_action', participation_answered_at=NOW() + WHERE id=$1 AND participation_status='pending'`, teamID) + return err +} + func (r *TeamsRepo) FinishParticipationEmail(ctx context.Context, id, attempt int, sendErr error) error { message := "" if sendErr != nil { diff --git a/internal/services/game_service/participation_test.go b/internal/services/game_service/participation_test.go index 9ee4106..972344b 100644 --- a/internal/services/game_service/participation_test.go +++ b/internal/services/game_service/participation_test.go @@ -106,6 +106,10 @@ func TestParticipationPostgres(t *testing.T) { state(3, "pending") state(4, "confirmed") state(5, "pending") + if err := repo.ConfirmParticipationByFirstAction(ctx, 5); err != nil { + t.Fatal(err) + } + state(5, "confirmed") // Independent workers must claim each due team just once. var wg sync.WaitGroup ids := make(chan int, 8) diff --git a/internal/services/game_service/service.go b/internal/services/game_service/service.go index 4563054..5e1d476 100644 --- a/internal/services/game_service/service.go +++ b/internal/services/game_service/service.go @@ -299,6 +299,11 @@ func (s *GameService) AddTeamAction(ctx context.Context, teamId int, password st if err != nil { return err } + if team.ParticipationStatus == "pending" { + if err := s.teamsRepo.ConfirmParticipationByFirstAction(ctx, teamId); err != nil { + return err + } + } game, err := s.gamesRepo.GetGameByID(ctx, team.GameId) if err != nil {