Coverage for bc/kwai-bc-training/src/kwai_bc_training/update_coach_training.py: 62%
21 statements
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
1"""Module that defines the use case for adding a coach to a training."""
3from dataclasses import dataclass
5from kwai_core.domain.presenter import Presenter
6from kwai_core.domain.value_objects.unique_id import UniqueId
8from kwai_bc_training.trainings.training import TrainingEntity, TrainingIdentifier
9from kwai_bc_training.trainings.training_repository import TrainingRepository
12@dataclass(kw_only=True, frozen=True, slots=True)
13class UpdateCoachTrainingCommand:
14 """Input for the use case."""
16 training_id: int
17 coach_uuid: str
18 head: bool
19 present: bool = False
20 payed: bool = False
21 remark: str = ""
24class UpdateCoachTraining:
25 """Update a coach to of a training."""
27 def __init__(
28 self,
29 training_repo: TrainingRepository,
30 presenter: Presenter[TrainingEntity],
31 ):
32 """Initialize the use case.
34 Attributes:
35 training_repo: Repository for trainings
36 presenter: Presenter for a training.
37 """
38 self._training_repo = training_repo
39 self._presenter = presenter
41 async def execute(self, command: UpdateCoachTrainingCommand):
42 """Execute the use case.
44 Args:
45 command: the input for this use case.
47 Raises:
48 TrainingNotFoundException: Raised when the training doesn't exist.
49 ValueError: Raised when the coach isn't appointed to this training.
50 """
51 training = await self._training_repo.get_by_id(
52 TrainingIdentifier(command.training_id)
53 )
55 unique_id_of_coach = UniqueId.create_from_string(command.coach_uuid)
57 training = training.mark_coach_as_present(unique_id_of_coach, command.present)
58 training = training.appoint_head_coach(unique_id_of_coach, command.head)
59 await self._training_repo.update(training)
61 self._presenter.present(training)