Coverage for bc/kwai-bc-identity/src/kwai_bc_identity/user_invitations/user_invitation_repository.py: 100%
7 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 an interface for an invitation repository."""
3from abc import ABC, abstractmethod
4from typing import AsyncIterator
6from kwai_core.domain.value_objects.unique_id import UniqueId
8from kwai_bc_identity.user_invitations.user_invitation import (
9 UserInvitationEntity,
10 UserInvitationIdentifier,
11)
12from kwai_bc_identity.user_invitations.user_invitation_query import (
13 UserInvitationQuery,
14)
17class UserInvitationNotFoundException(Exception):
18 """Raised when the invitation could not be found."""
21class UserInvitationRepository(ABC):
22 """An invitation repository interface."""
24 @abstractmethod
25 def create_query(self) -> UserInvitationQuery:
26 """Create a UserInvitationQuery.
28 Returns:
29 A query for user invitations.
30 """
31 raise NotImplementedError
33 @abstractmethod
34 def get_all(
35 self,
36 query: UserInvitationQuery,
37 limit: int | None = None,
38 offset: int | None = None,
39 ) -> AsyncIterator[UserInvitationEntity]:
40 """Return all user invitations from the query.
42 Args:
43 query: The prepared query.
44 limit: The maximum number of entities to return.
45 offset: Skip the offset rows before beginning to return entities.
47 Yields:
48 A list of user invitation entities.
49 """
50 raise NotImplementedError
52 @abstractmethod
53 async def get_invitation_by_id(
54 self, id_: UserInvitationIdentifier
55 ) -> UserInvitationEntity:
56 """Get an invitation using the id.
58 Args:
59 id_: The id of the invitation to search for.
60 """
61 raise NotImplementedError
63 @abstractmethod
64 async def get_invitation_by_uuid(self, uuid: UniqueId) -> UserInvitationEntity:
65 """Get an invitation using the unique id.
67 Args:
68 uuid: The unique id to use for searching the invitation.
69 """
70 raise NotImplementedError
72 @abstractmethod
73 async def create(self, invitation: UserInvitationEntity) -> UserInvitationEntity:
74 """Create a new invitation.
76 Args:
77 invitation: The invitation to create.
78 """
79 raise NotImplementedError
81 @abstractmethod
82 async def update(self, invitation: UserInvitationEntity) -> None:
83 """Update an existing invitation.
85 Args:
86 invitation: The invitation to update.
87 """
88 raise NotImplementedError
90 @abstractmethod
91 async def delete(self, invitation: UserInvitationEntity) -> None:
92 """Delete the invitation.
94 Args:
95 invitation: The invitation to delete.
96 """
97 raise NotImplementedError