Coverage for bc/kwai-bc-club/src/kwai_bc_club/get_user_coach.py: 93%
15 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"""Use case for getting the coach from a user."""
3from dataclasses import dataclass
5from kwai_core.domain.presenter import Presenter
6from kwai_core.domain.value_objects.unique_id import UniqueId
8from kwai_bc_club.domain.club_coach import ClubCoachEntity
9from kwai_bc_club.repositories.coach_repository import CoachRepository
12@dataclass(frozen=True, slots=True, kw_only=True)
13class GetUserCoachCommand:
14 """The input for the use case."""
16 uuid: str
19class GetUserCoach:
20 """The use case for getting the coach from a user."""
22 def __init__(
23 self, coach_repo: CoachRepository, presenter: Presenter[ClubCoachEntity]
24 ) -> None:
25 """Initialize the use case."""
26 self._coach_repo = coach_repo
27 self._presenter = presenter
29 async def execute(self, command: GetUserCoachCommand) -> None:
30 """Execute the use case.
32 Raises:
33 CoachNotFoundException: If the user is not attached to a coach.
34 """
35 query = self._coach_repo.create_query().filter_by_user_uuid(
36 UniqueId.create_from_string(command.uuid)
37 )
38 coach = await self._coach_repo.get(query)
39 self._presenter.present(coach)