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

13 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-09-05 17:55 +0000

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

2from dataclasses import dataclass 

3 

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

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

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

7 UserInvitationRepository, 

8) 

9 

10 

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

12class GetUserInvitationCommand: 

13 """Input for the use case. 

14 

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

16 

17 Attributes: 

18 uuid: The unique id of the user invitation. 

19 """ 

20 

21 uuid: str 

22 

23 

24class GetUserInvitation: 

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

26 

27 def __init__(self, user_invitation_repo: UserInvitationRepository): 

28 """Initialize the use case. 

29 

30 Args: 

31 user_invitation_repo: A repository for getting the user invitation. 

32 """ 

33 self._user_invitation_repo = user_invitation_repo 

34 

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

36 """Execute the use case. 

37 

38 Args: 

39 command: The input for this use case. 

40 

41 Returns: 

42 A user invitation entity 

43 

44 Raises: 

45 UserInvitationNotFoundException: Raised when then invitation is not found. 

46 """ 

47 entity = await self._user_invitation_repo.get_invitation_by_uuid( 

48 UniqueId.create_from_string(command.uuid) 

49 ) 

50 return entity