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

1"""Module for defining the use case 'get coaches'.""" 

2 

3from dataclasses import dataclass 

4 

5from kwai.core.domain.use_case import UseCaseBrowseResult 

6from kwai.modules.training.coaches.coach_repository import CoachRepository 

7 

8 

9@dataclass(kw_only=True, frozen=True, slots=True) 

10class GetCoachesCommand: 

11 """Input for the use case GetCoaches.""" 

12 

13 active: bool 

14 

15 

16class GetCoaches: 

17 """Use case for getting coaches.""" 

18 

19 def __init__(self, coach_repo: CoachRepository): 

20 """Initialize the use case. 

21 

22 Args: 

23 coach_repo: The repository for getting the coaches. 

24 """ 

25 self._coach_repo = coach_repo 

26 

27 async def execute(self, command: GetCoachesCommand) -> UseCaseBrowseResult: 

28 """Execute the use case.""" 

29 coach_query = self._coach_repo.create_query() 

30 

31 if command.active: 

32 coach_query.filter_by_active() 

33 

34 count = await coach_query.count() 

35 

36 return UseCaseBrowseResult( 

37 count=count, 

38 iterator=self._coach_repo.get_all(coach_query), 

39 )