generated from VLADIMIR/template
fix
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
package participation_service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"evening_detective_server/internal/repos/teams_repo"
|
||||
)
|
||||
|
||||
// Participation — данные участия, доступные транспортному и email-сценариям.
|
||||
@@ -20,7 +19,8 @@ type Participation struct {
|
||||
}
|
||||
|
||||
var (
|
||||
ErrParticipationLink = teams_repo.ErrParticipationLink
|
||||
ErrParticipationClosed = teams_repo.ErrParticipationClosed
|
||||
ErrParticipationFinal = teams_repo.ErrParticipationFinal
|
||||
ErrParticipationLink = errors.New("Ссылка недействительна")
|
||||
ErrParticipationClosed = errors.New("Приём ответов закрыт")
|
||||
ErrParticipationFinal = errors.New("Решение уже принято и не может быть изменено")
|
||||
ErrInvalidAnswer = errors.New("Выберите подтверждение или отмену участия")
|
||||
)
|
||||
|
||||
@@ -30,11 +30,26 @@ func NewParticipationService(teamsRepo *teams_repo.TeamsRepo, appBaseURL string)
|
||||
|
||||
func (s *ParticipationService) GetParticipation(ctx context.Context, token string) (*Participation, error) {
|
||||
p, err := s.teamsRepo.GetParticipation(ctx, token)
|
||||
return mapParticipation(p), err
|
||||
return mapParticipation(p), mapParticipationError(err)
|
||||
}
|
||||
func (s *ParticipationService) AnswerParticipation(ctx context.Context, token, answer string) (*Participation, error) {
|
||||
p, err := s.teamsRepo.AnswerParticipation(ctx, token, answer)
|
||||
return mapParticipation(p), err
|
||||
return mapParticipation(p), mapParticipationError(err)
|
||||
}
|
||||
|
||||
func mapParticipationError(err error) error {
|
||||
switch {
|
||||
case errors.Is(err, teams_repo.ErrParticipationLink):
|
||||
return ErrParticipationLink
|
||||
case errors.Is(err, teams_repo.ErrParticipationClosed):
|
||||
return ErrParticipationClosed
|
||||
case errors.Is(err, teams_repo.ErrParticipationFinal):
|
||||
return ErrParticipationFinal
|
||||
case err != nil && err.Error() == ErrInvalidAnswer.Error():
|
||||
return ErrInvalidAnswer
|
||||
default:
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Стабильные токены для разных целей сохраняют работоспособность ссылок при
|
||||
|
||||
Reference in New Issue
Block a user