This commit is contained in:
2026-10-02 01:06:19 +07:00
parent d85967968f
commit cbc8656d3e
5 changed files with 64 additions and 15 deletions
@@ -28,11 +28,13 @@ func NewParticipationService(teamsRepo *teams_repo.TeamsRepo, appBaseURL string)
return &ParticipationService{teamsRepo: teamsRepo, appBaseURL: appBaseURL}
}
func (s *ParticipationService) GetParticipation(ctx context.Context, token string) (*teams_repo.Participation, error) {
return s.teamsRepo.GetParticipation(ctx, token)
func (s *ParticipationService) GetParticipation(ctx context.Context, token string) (*Participation, error) {
p, err := s.teamsRepo.GetParticipation(ctx, token)
return mapParticipation(p), err
}
func (s *ParticipationService) AnswerParticipation(ctx context.Context, token, answer string) (*teams_repo.Participation, error) {
return s.teamsRepo.AnswerParticipation(ctx, token, answer)
func (s *ParticipationService) AnswerParticipation(ctx context.Context, token, answer string) (*Participation, error) {
p, err := s.teamsRepo.AnswerParticipation(ctx, token, answer)
return mapParticipation(p), err
}
// Стабильные токены для разных целей сохраняют работоспособность ссылок при
@@ -45,7 +47,7 @@ func participationToken(secret string, id int) string {
return hex.EncodeToString(mac.Sum(nil))
}
func participationEmail(p *teams_repo.Participation, baseURL, token string, location *time.Location) email_sender.Message {
func participationEmail(p *Participation, baseURL, token string, location *time.Location) email_sender.Message {
link := strings.TrimRight(baseURL, "/") + "/participation#token=" + token
date := p.StartAt.In(location).Format("02.01.2006 в 15:04 (MST, UTC-07:00)")
body := fmt.Sprintf("Команда «%s», подтвердите участие в игре «%s».\nДата: %s\nУчастников: %d\n\nПодтвердить участие: %s&answer=confirmed\nОтменить участие: %s&answer=cancelled\n\nОтвет можно дать до начала игры. Решение окончательное: изменить его нельзя. Без ответа запись сохраняется со статусом «Ожидает ответа».\nНе пересылайте письмо: ссылка позволяет принять решение за команду.", p.TeamName, p.GameName, date, p.ParticipantsCount, link, link)
@@ -89,7 +91,7 @@ func (s *ParticipationService) RunParticipationEmails(ctx context.Context, sende
func (s *ParticipationService) sendParticipationEmails(ctx context.Context, sender email_sender.IEmailSender, secret string, location *time.Location) error {
for ctx.Err() == nil {
jobCtx, cancel := context.WithTimeout(ctx, time.Minute)
p, err := s.teamsRepo.ClaimParticipationEmail(jobCtx)
repoParticipation, err := s.teamsRepo.ClaimParticipationEmail(jobCtx)
if errors.Is(err, pgx.ErrNoRows) {
cancel()
return nil
@@ -98,6 +100,7 @@ func (s *ParticipationService) sendParticipationEmails(ctx context.Context, send
cancel()
return err
}
p := mapParticipation(repoParticipation)
token := participationToken(secret, p.TeamID)
err = s.teamsRepo.SetParticipationToken(jobCtx, p.TeamID, token)
if err == nil {