Coverage for src/kwai/modules/club/get_member.py: 100%

17 statements  

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

1"""Module that implements the use case 'Get Member'.""" 

2 

3from dataclasses import dataclass 

4 

5from kwai.core.domain.presenter import Presenter 

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

7from kwai.modules.club.domain.member import MemberEntity 

8from kwai.modules.club.repositories.member_repository import MemberRepository 

9 

10 

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

12class GetMemberCommand: 

13 """The input for the use case 'Get Member'. 

14 

15 Attributes: 

16 uuid: The unique id of the member. 

17 """ 

18 

19 uuid: str 

20 

21 

22class GetMember: 

23 """Use case 'Get Member'.""" 

24 

25 def __init__(self, repo: MemberRepository, presenter: Presenter[MemberEntity]): 

26 """Initialize the use case. 

27 

28 Args: 

29 repo: The repository used to get the member. 

30 presenter: The presenter used to handle the result of the use case. 

31 """ 

32 self._repo = repo 

33 self._presenter = presenter 

34 

35 async def execute(self, command: GetMemberCommand) -> None: 

36 """Execute the use case. 

37 

38 Args: 

39 command: the input for this use case. 

40 

41 Returns: 

42 The member (if it exists) with the given uuid. 

43 

44 Throws: 

45 MemberNotFoundException: raised when the member does not exist. 

46 """ 

47 query = self._repo.create_query() 

48 query.filter_by_uuid(UniqueId.create_from_string(command.uuid)) 

49 

50 member = await self._repo.get(query) 

51 self._presenter.present(member)