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

1"""Module that defines an interface for an invitation repository.""" 

2 

3from abc import ABC, abstractmethod 

4from typing import AsyncIterator 

5 

6from kwai_core.domain.value_objects.unique_id import UniqueId 

7 

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) 

15 

16 

17class UserInvitationNotFoundException(Exception): 

18 """Raised when the invitation could not be found.""" 

19 

20 

21class UserInvitationRepository(ABC): 

22 """An invitation repository interface.""" 

23 

24 @abstractmethod 

25 def create_query(self) -> UserInvitationQuery: 

26 """Create a UserInvitationQuery. 

27 

28 Returns: 

29 A query for user invitations. 

30 """ 

31 raise NotImplementedError 

32 

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. 

41 

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. 

46 

47 Yields: 

48 A list of user invitation entities. 

49 """ 

50 raise NotImplementedError 

51 

52 @abstractmethod 

53 async def get_invitation_by_id( 

54 self, id_: UserInvitationIdentifier 

55 ) -> UserInvitationEntity: 

56 """Get an invitation using the id. 

57 

58 Args: 

59 id_: The id of the invitation to search for. 

60 """ 

61 raise NotImplementedError 

62 

63 @abstractmethod 

64 async def get_invitation_by_uuid(self, uuid: UniqueId) -> UserInvitationEntity: 

65 """Get an invitation using the unique id. 

66 

67 Args: 

68 uuid: The unique id to use for searching the invitation. 

69 """ 

70 raise NotImplementedError 

71 

72 @abstractmethod 

73 async def create(self, invitation: UserInvitationEntity) -> UserInvitationEntity: 

74 """Create a new invitation. 

75 

76 Args: 

77 invitation: The invitation to create. 

78 """ 

79 raise NotImplementedError 

80 

81 @abstractmethod 

82 async def update(self, invitation: UserInvitationEntity) -> None: 

83 """Update an existing invitation. 

84 

85 Args: 

86 invitation: The invitation to update. 

87 """ 

88 raise NotImplementedError 

89 

90 @abstractmethod 

91 async def delete(self, invitation: UserInvitationEntity) -> None: 

92 """Delete the invitation. 

93 

94 Args: 

95 invitation: The invitation to delete. 

96 """ 

97 raise NotImplementedError