Coverage for bc/kwai-bc-identity/src/kwai_bc_identity/users/user_account_repository.py: 100%
9 statements
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.11.0, 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_core.domain.value_objects.unique_id import UniqueId
9from kwai_bc_identity.users.user_account import UserAccountEntity
10from kwai_bc_identity.users.user_account_query import UserAccountQuery
13class UserAccountRepository:
14 """Interface for a user account repository."""
16 @abstractmethod
17 def get_all(
18 self,
19 query: UserAccountQuery | None = None,
20 limit: int | None = None,
21 offset: int | None = None,
22 ) -> AsyncGenerator[UserAccountEntity, None]:
23 """Return all user accounts.
25 Args:
26 query: Query to filter user accounts.
27 limit: The maximum number of entities to return.
28 offset: Skip the offset rows before beginning to return entities.
30 Yields:
31 A list of user account entities.
32 """
33 raise NotImplementedError
35 @abstractmethod
36 def create_query(self) -> UserAccountQuery:
37 """Return a new user account query.
39 Returns:
40 A query for user accounts.
41 """
42 raise NotImplementedError
44 @abstractmethod
45 async def get_user_by_email(self, email: EmailAddress) -> UserAccountEntity:
46 """Get a user account with the given email address.
48 Raises:
49 UserAccountNotFoundException: If no user account with the given email address exists.
50 """
51 raise NotImplementedError
53 async def exists_with_email(self, email: EmailAddress) -> bool:
54 """Check if a user account with the given email address already exists.
56 Args:
57 email: The email address to check.
59 Returns:
60 True when a user with the given email address exists.
61 """
62 raise NotImplementedError
64 @abstractmethod
65 async def get_user_by_uuid(self, uuid: UniqueId) -> UserAccountEntity:
66 """Get a user account using the unique id.
68 Raises:
69 UserAccountNotFoundException: If no user account with the given uuid exists.
70 """
71 raise NotImplementedError
73 @abstractmethod
74 async def create(self, user_account: UserAccountEntity) -> UserAccountEntity:
75 """Save a new user account."""
76 raise NotImplementedError
78 @abstractmethod
79 async def update(self, user_account: UserAccountEntity):
80 """Save a user account."""
81 raise NotImplementedError
83 @abstractmethod
84 async def delete(self, user_account):
85 """Delete a user account."""
86 raise NotImplementedError
89class UserAccountNotFoundException(Exception):
90 """Raised when a user account cannot be found."""