Coverage for src/kwai/modules/teams/repositories/team_repository.py: 100%
8 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 team repository."""
3from abc import ABC, abstractmethod
4from typing import AsyncGenerator, Self
6from kwai.core.domain.repository.query import Query
7from kwai.modules.teams.domain.team import TeamEntity, TeamIdentifier
8from kwai.modules.teams.domain.team_member import TeamMember
11class TeamNotFoundException(Exception):
12 """Raised when a team cannot be found."""
15class TeamQuery(Query, ABC):
16 """An interface for a team query."""
18 @abstractmethod
19 def filter_by_id(self, id_: TeamIdentifier) -> Self:
20 """Find a team by its id."""
21 raise NotImplementedError
24class TeamRepository(ABC):
25 """An interface for a team repository."""
27 @abstractmethod
28 def create_query(self) -> TeamQuery:
29 """Create a team query."""
30 raise NotImplementedError
32 @abstractmethod
33 async def get(self, query: TeamQuery | None = None) -> TeamEntity:
34 """Return the first returned element of the given query.
36 Args:
37 query: The query to use for getting the first team.
39 Raises:
40 TeamNotFoundException: If the team cannot be found.
41 """
42 raise NotImplementedError
44 @abstractmethod
45 def get_all(
46 self,
47 query: TeamQuery | None = None,
48 limit: int | None = None,
49 offset: int | None = None,
50 ) -> AsyncGenerator[TeamEntity, None]:
51 """Return all teams of the given query.
53 Args:
54 query: The query to use for getting the teams.
55 limit: The maximum number of teams to return.
56 offset: The offset to use for fetching teams.
58 Yields:
59 A team entity.
61 """
62 raise NotImplementedError
64 @abstractmethod
65 async def create(self, team: TeamEntity) -> TeamEntity:
66 """Save a new team."""
68 @abstractmethod
69 async def delete(self, team: TeamEntity) -> None:
70 """Delete a team."""
72 @abstractmethod
73 async def update(self, team: TeamEntity) -> None:
74 """Update a team."""
76 @abstractmethod
77 async def add_team_member(self, team: TeamEntity, member: TeamMember):
78 """Add a member to a team."""