Coverage for src/kwai/modules/identity/get_user_accounts.py: 73%
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 the get user accounts use case."""
3from dataclasses import dataclass
5from kwai.core.domain.presenter import AsyncPresenter, IterableResult
6from kwai.modules.identity.users.user_account import UserAccountEntity
7from kwai.modules.identity.users.user_account_repository import UserAccountRepository
10@dataclass(kw_only=True, frozen=True, slots=True)
11class GetUserAccountsCommand:
12 """Input for the use case.
14 Attributes:
15 offset: Offset from where to start the query of user accounts.
16 limit: The maximum number of users to return.
17 """
19 offset: int | None = None
20 limit: int | None = None
23class GetUserAccounts:
24 """Implementation of the get user accounts use case."""
26 def __init__(
27 self,
28 user_account_repo: UserAccountRepository,
29 presenter: AsyncPresenter[IterableResult[UserAccountEntity]],
30 ):
31 """Initialize the get users use case."""
32 self._user_account_repo = user_account_repo
33 self._presenter = presenter
35 async def execute(self, command: GetUserAccountsCommand):
36 """Execute the get users use case.
38 Args:
39 command: Input for the use case.
40 """
41 query = self._user_account_repo.create_query()
43 await self._presenter.present(
44 IterableResult(
45 count=await query.count(),
46 limit=command.limit,
47 offset=command.offset,
48 iterator=self._user_account_repo.get_all(
49 query, command.limit, command.offset
50 ),
51 )
52 )