Coverage for src/kwai/modules/identity/user_invitations/user_invitation_repository.py: 100%
7 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 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
7from kwai.modules.identity.user_invitations.user_invitation import (
8 UserInvitationEntity,
9 UserInvitationIdentifier,
10)
11from kwai.modules.identity.user_invitations.user_invitation_query import (
12 UserInvitationQuery,
13)
16class UserInvitationNotFoundException(Exception):
17 """Raised when the invitation could not be found."""
20class UserInvitationRepository(ABC):
21 """An invitation repository interface."""
23 @abstractmethod
24 def create_query(self) -> UserInvitationQuery:
25 """Create a UserInvitationQuery.
27 Returns:
28 A query for user invitations.
29 """
30 raise NotImplementedError
32 @abstractmethod
33 async def get_all(
34 self,
35 query: UserInvitationQuery,
36 limit: int | None = None,
37 offset: int | None = None,
38 ) -> AsyncIterator[UserInvitationEntity]:
39 """Return all user invitations from the query.
41 Args:
42 query: The prepared query.
43 limit: The maximum number of entities to return.
44 offset: Skip the offset rows before beginning to return entities.
46 Yields:
47 A list of user invitation entities.
48 """
49 raise NotImplementedError
51 @abstractmethod
52 async def get_invitation_by_id(
53 self, id_: UserInvitationIdentifier
54 ) -> UserInvitationEntity:
55 """Get an invitation using the id.
57 Args:
58 id_: The id of the invitation to search for.
59 """
60 raise NotImplementedError
62 @abstractmethod
63 async def get_invitation_by_uuid(self, uuid: UniqueId) -> UserInvitationEntity:
64 """Get an invitation using the unique id.
66 Args:
67 uuid: The unique id to use for searching the invitation.
68 """
69 raise NotImplementedError
71 @abstractmethod
72 async def create(self, invitation: UserInvitationEntity) -> UserInvitationEntity:
73 """Create a new invitation.
75 Args:
76 invitation: The invitation to create.
77 """
78 raise NotImplementedError
80 @abstractmethod
81 async def update(self, invitation: UserInvitationEntity) -> None:
82 """Update an existing invitation.
84 Args:
85 invitation: The invitation to update.
86 """
87 raise NotImplementedError
89 @abstractmethod
90 async def delete(self, invitation: UserInvitationEntity) -> None:
91 """Delete the invitation.
93 Args:
94 invitation: The invitation to delete.
95 """
96 raise NotImplementedError