Coverage for src/kwai/modules/identity/get_user_invitation.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-01-01 00:00 +0000

1"""Implement the use case: get a user invitation.""" 

2 

3from dataclasses import dataclass 

4 

5from kwai.core.domain.value_objects.unique_id import UniqueId 

6from kwai.modules.identity.user_invitations.user_invitation import UserInvitationEntity 

7from kwai.modules.identity.user_invitations.user_invitation_repository import ( 

8 UserInvitationRepository, 

9) 

10 

11 

12@dataclass(kw_only=True, frozen=True, slots=True) 

13class GetUserInvitationCommand: 

14 """Input for the use case. 

15 

16 [GetUserInvitation][kwai.modules.identity.get_user_invitation.GetUserInvitation] 

17 

18 Attributes: 

19 uuid: The unique id of the user invitation. 

20 """ 

21 

22 uuid: str 

23 

24 

25class GetUserInvitation: 

26 """Implements the use case 'get a user invitation'.""" 

27 

28 def __init__(self, user_invitation_repo: UserInvitationRepository): 

29 """Initialize the use case. 

30 

31 Args: 

32 user_invitation_repo: A repository for getting the user invitation. 

33 """ 

34 self._user_invitation_repo = user_invitation_repo 

35 

36 async def execute(self, command: GetUserInvitationCommand) -> UserInvitationEntity: 

37 """Execute the use case. 

38 

39 Args: 

40 command: The input for this use case. 

41 

42 Returns: 

43 A user invitation entity 

44 

45 Raises: 

46 UserInvitationNotFoundException: Raised when then invitation is not found. 

47 """ 

48 entity = await self._user_invitation_repo.get_invitation_by_uuid( 

49 UniqueId.create_from_string(command.uuid) 

50 ) 

51 return entity