Coverage for bc/kwai-bc-club/src/kwai_bc_club/get_coaches.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 the use case 'Get Coaches'."""
3from dataclasses import dataclass
5from kwai_core.domain.presenter import AsyncPresenter, IterableResult
7from kwai_bc_club.domain.club_coach import ClubCoachEntity
8from kwai_bc_club.repositories.coach_repository import CoachRepository
11@dataclass(frozen=True, kw_only=True, slots=True)
12class GetCoachesCommand:
13 """Input for the use case."""
15 offset: int
16 limit: int
17 active: bool = True
20class GetCoaches:
21 """Use case 'Get Coaches'."""
23 def __init__(
24 self,
25 coach_repo: CoachRepository,
26 presenter: AsyncPresenter[IterableResult[ClubCoachEntity]],
27 ):
28 """Initialize the use case."""
29 self._coach_repo = coach_repo
30 self._presenter = presenter
32 async def execute(self, command: GetCoachesCommand) -> None:
33 """Execute the use case."""
34 query = self._coach_repo.create_query()
36 if command.active:
37 query = query.filter_by_active()
39 await self._presenter.present(
40 IterableResult(
41 count=await query.count(),
42 limit=command.limit,
43 offset=command.offset,
44 iterator=self._coach_repo.get_all(query),
45 )
46 )