Coverage for src/kwai/modules/training/get_coaches.py: 100%
15 statements
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
1"""Module for defining the use case 'get coaches'."""
3from dataclasses import dataclass
5from kwai.core.domain.use_case import UseCaseBrowseResult
6from kwai.modules.training.coaches.coach_repository import CoachRepository
9@dataclass(kw_only=True, frozen=True, slots=True)
10class GetCoachesCommand:
11 """Input for the use case GetCoaches."""
13 active: bool
16class GetCoaches:
17 """Use case for getting coaches."""
19 def __init__(self, coach_repo: CoachRepository):
20 """Initialize the use case.
22 Args:
23 coach_repo: The repository for getting the coaches.
24 """
25 self._coach_repo = coach_repo
27 async def execute(self, command: GetCoachesCommand) -> UseCaseBrowseResult:
28 """Execute the use case."""
29 coach_query = self._coach_repo.create_query()
31 if command.active:
32 coach_query.filter_by_active()
34 count = await coach_query.count()
36 return UseCaseBrowseResult(
37 count=count,
38 iterator=self._coach_repo.get_all(coach_query),
39 )