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

7 statements  

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

1"""Module that defines an interface for a Member repository.""" 

2 

3from abc import ABC, abstractmethod 

4from typing import AsyncGenerator 

5 

6from kwai.modules.club.domain.file_upload import FileUploadEntity 

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

8from kwai.modules.club.repositories.member_query import MemberQuery 

9 

10 

11class MemberNotFoundException(Exception): 

12 """Raised when a Member cannot be found.""" 

13 

14 

15class MemberRepository(ABC): 

16 """An interface for a repository of members.""" 

17 

18 @abstractmethod 

19 def create_query(self) -> MemberQuery: 

20 """Create a query for querying members.""" 

21 raise NotImplementedError 

22 

23 @abstractmethod 

24 async def get(self, query: MemberQuery | None = None) -> MemberEntity: 

25 """Return the first returned element of the given query. 

26 

27 Args: 

28 query: The query to use for getting the first member. 

29 

30 Raises: 

31 MemberNotFoundException: Raised when the member is not found. 

32 """ 

33 raise NotImplementedError 

34 

35 @abstractmethod 

36 def get_all( 

37 self, 

38 query: MemberQuery | None = None, 

39 limit: int | None = None, 

40 offset: int | None = None, 

41 ) -> AsyncGenerator[MemberEntity, None]: 

42 """Return all members of a given query. 

43 

44 Args: 

45 query: The query to use for selecting the members. 

46 limit: The maximum number of entities to return. 

47 offset: Skip the offset rows before beginning to return entities. 

48 

49 Yields: 

50 A member entity. 

51 """ 

52 raise NotImplementedError 

53 

54 @abstractmethod 

55 async def create(self, member: MemberEntity) -> MemberEntity: 

56 """Create a member. 

57 

58 Args: 

59 member: The member to save. 

60 

61 Returns: 

62 A member entity with an identifier. 

63 """ 

64 raise NotImplementedError 

65 

66 @abstractmethod 

67 async def update(self, member: MemberEntity) -> None: 

68 """Update a member. 

69 

70 Args: 

71 member: The member to update. 

72 """ 

73 raise NotImplementedError 

74 

75 @abstractmethod 

76 async def delete(self, member: MemberEntity) -> None: 

77 """Delete a member. 

78 

79 Args: 

80 member: The member to delete. 

81 """ 

82 raise NotImplementedError 

83 

84 @abstractmethod 

85 async def activate_members(self, upload: FileUploadEntity) -> None: 

86 """Activate all members that have been uploaded.""" 

87 raise NotImplementedError 

88 

89 @abstractmethod 

90 async def deactivate_members(self, upload: FileUploadEntity) -> None: 

91 """Deactivate all members that are not being uploaded.""" 

92 raise NotImplementedError