Coverage for bc/kwai-bc-club/src/kwai_bc_club/update_coach.py: 100%
16 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 an 'Update Coach' use case."""
3from dataclasses import dataclass, replace
5from kwai_core.domain.presenter import Presenter
7from kwai_bc_club.coach_command import CoachCommand
8from kwai_bc_club.domain.club_coach import ClubCoachEntity, ClubCoachIdentifier
9from kwai_bc_club.repositories.coach_repository import CoachRepository
12@dataclass(kw_only=True, frozen=True, slots=True)
13class UpdateCoachCommand(CoachCommand):
14 """Input for the update Coach use case."""
16 id: int
19class UpdateCoach:
20 """Update Coach use case."""
22 def __init__(
23 self, coach_repo: CoachRepository, presenter: Presenter[ClubCoachEntity]
24 ):
25 """Initialize the use case."""
26 self._coach_repo = coach_repo
27 self._presenter = presenter
29 async def execute(self, command: UpdateCoachCommand) -> None:
30 """Execute the use case.
32 Raises:
33 CoachNotFoundException: Raised when a coach cannot be found.
34 """
35 coach = await self._coach_repo.get_by_id(ClubCoachIdentifier(command.id))
37 coach = replace(
38 coach,
39 diploma=command.diploma,
40 description=command.description,
41 remark=command.remark,
42 active=command.active,
43 )
45 await self._coach_repo.update(coach)
46 self._presenter.present(coach)