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
« 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."""
3from abc import ABC, abstractmethod
4from typing import AsyncGenerator
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
11class MemberNotFoundException(Exception):
12 """Raised when a Member cannot be found."""
15class MemberRepository(ABC):
16 """An interface for a repository of members."""
18 @abstractmethod
19 def create_query(self) -> MemberQuery:
20 """Create a query for querying members."""
21 raise NotImplementedError
23 @abstractmethod
24 async def get(self, query: MemberQuery | None = None) -> MemberEntity:
25 """Return the first returned element of the given query.
27 Args:
28 query: The query to use for getting the first member.
30 Raises:
31 MemberNotFoundException: Raised when the member is not found.
32 """
33 raise NotImplementedError
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.
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.
49 Yields:
50 A member entity.
51 """
52 raise NotImplementedError
54 @abstractmethod
55 async def create(self, member: MemberEntity) -> MemberEntity:
56 """Create a member.
58 Args:
59 member: The member to save.
61 Returns:
62 A member entity with an identifier.
63 """
64 raise NotImplementedError
66 @abstractmethod
67 async def update(self, member: MemberEntity) -> None:
68 """Update a member.
70 Args:
71 member: The member to update.
72 """
73 raise NotImplementedError
75 @abstractmethod
76 async def delete(self, member: MemberEntity) -> None:
77 """Delete a member.
79 Args:
80 member: The member to delete.
81 """
82 raise NotImplementedError
84 @abstractmethod
85 async def activate_members(self, upload: FileUploadEntity) -> None:
86 """Activate all members that have been uploaded."""
87 raise NotImplementedError
89 @abstractmethod
90 async def deactivate_members(self, upload: FileUploadEntity) -> None:
91 """Deactivate all members that are not being uploaded."""
92 raise NotImplementedError