Coverage for src/kwai/modules/teams/get_teams.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-01-01 00:00 +0000

1"""Module that implements the use case 'Get Teams'.""" 

2 

3from dataclasses import dataclass 

4 

5from kwai.core.domain.presenter import AsyncPresenter, IterableResult 

6from kwai.modules.teams.domain.team import TeamEntity 

7from kwai.modules.teams.repositories.team_repository import TeamRepository 

8 

9 

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

11class GetTeamsCommand: 

12 """Input for the use case 'Get Teams'.""" 

13 

14 offset: int | None = None 

15 limit: int | None = None 

16 

17 

18class GetTeams: 

19 """Implement the use case 'Get Teams'.""" 

20 

21 def __init__( 

22 self, 

23 team_repo: TeamRepository, 

24 presenter: AsyncPresenter[IterableResult[TeamEntity]], 

25 ): 

26 """Initialize the use case.""" 

27 self._team_repo = team_repo 

28 self._presenter = presenter 

29 

30 async def execute(self, command: GetTeamsCommand) -> None: 

31 """Execute the use case.""" 

32 query = self._team_repo.create_query() 

33 await self._presenter.present( 

34 IterableResult( 

35 count=await query.count(), 

36 limit=command.limit, 

37 offset=command.offset, 

38 iterator=self._team_repo.get_all(query, command.offset, command.limit), 

39 ) 

40 )