Coverage for bc/kwai-bc-club/src/kwai_bc_club/get_member.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.11.0, 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 

7 

8from kwai_bc_club.domain.member import MemberEntity 

9from kwai_bc_club.repositories.member_repository import MemberRepository 

10 

11 

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

13class GetMemberCommand: 

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

15 

16 Attributes: 

17 uuid: The unique id of the member. 

18 """ 

19 

20 uuid: str 

21 

22 

23class GetMember: 

24 """Use case 'Get Member'.""" 

25 

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

27 """Initialize the use case. 

28 

29 Args: 

30 repo: The repository used to get the member. 

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

32 """ 

33 self._repo = repo 

34 self._presenter = presenter 

35 

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

37 """Execute the use case. 

38 

39 Args: 

40 command: the input for this use case. 

41 

42 Returns: 

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

44 

45 Throws: 

46 MemberNotFoundException: raised when the member does not exist. 

47 """ 

48 query = self._repo.create_query() 

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

50 

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

52 self._presenter.present(member)