Coverage for src/kwai/modules/identity/users/user_account_repository.py: 100%
8 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 that defines a repository for a user account."""
3from abc import abstractmethod
4from collections.abc import AsyncGenerator
6from kwai.core.domain.value_objects.email_address import EmailAddress
7from kwai.modules.identity.users.user_account import UserAccountEntity
8from kwai.modules.identity.users.user_account_query import UserAccountQuery
11class UserAccountRepository:
12 """Interface for a user account repository."""
14 @abstractmethod
15 async def get_all(
16 self, limit: int | None = None, offset: int | None = None
17 ) -> AsyncGenerator[UserAccountEntity, None]:
18 """Return all user accounts.
20 Args:
21 limit: The maximum number of entities to return.
22 offset: Skip the offset rows before beginning to return entities.
24 Yields:
25 A list of user account entities.
26 """
27 raise NotImplementedError
29 @abstractmethod
30 def create_query(self) -> UserAccountQuery:
31 """Return a new user account query.
33 Returns:
34 A query for user accounts.
35 """
36 raise NotImplementedError
38 @abstractmethod
39 async def get_user_by_email(self, email: EmailAddress) -> UserAccountEntity:
40 """Get a user account with the given email address."""
41 raise NotImplementedError
43 async def exists_with_email(self, email: EmailAddress) -> bool:
44 """Check if a user account with the given email address already exists.
46 Args:
47 email: The email address to check.
49 Returns:
50 True when a user with the given email address exists.
51 """
52 raise NotImplementedError
54 @abstractmethod
55 async def create(self, user_account: UserAccountEntity) -> UserAccountEntity:
56 """Save a new user account."""
57 raise NotImplementedError
59 @abstractmethod
60 async def update(self, user_account: UserAccountEntity):
61 """Save a user account."""
62 raise NotImplementedError
64 @abstractmethod
65 async def delete(self, user_account):
66 """Delete a user account."""
67 raise NotImplementedError
70class UserAccountNotFoundException(Exception):
71 """Raised when a user account cannot be found."""