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

12 statements  

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

1"""Implement the use case: delete 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_repository import ( 

7 UserInvitationRepository, 

8) 

9 

10 

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

12class DeleteUserInvitationCommand: 

13 """Input for the use case. 

14 

15 [DeleteUserInvitation][kwai.modules.identity.delete_user_invitation.DeleteUserInvitation] 

16 

17 Attributes: 

18 uuid: The unique id of the user invitation. 

19 """ 

20 

21 uuid: str 

22 

23 

24class DeleteUserInvitation: 

25 """Implements the use case 'delete 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 deleting the user invitation. 

32 """ 

33 self._user_invitation_repo = user_invitation_repo 

34 

35 async def execute(self, command: DeleteUserInvitationCommand): 

36 """Execute the use case. 

37 

38 Args: 

39 command: The input for this use case. 

40 

41 Raises: 

42 UserInvitationNotFoundException: Raised when then invitation is not found. 

43 """ 

44 entity = await self._user_invitation_repo.get_invitation_by_uuid( 

45 UniqueId.create_from_string(command.uuid) 

46 ) 

47 await self._user_invitation_repo.delete(entity)