Coverage for bc/kwai-bc-club/src/kwai_bc_club/repositories/coach_repository.py: 100%
7 statements
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
1"""Module for defining an interface for a coach repository."""
3from abc import ABC, abstractmethod
4from typing import AsyncGenerator
6from kwai_bc_club.domain.club_coach import ClubCoachEntity, ClubCoachIdentifier
7from kwai_bc_club.repositories.coach_query import CoachQuery
10class CoachNotFoundException(Exception):
11 """Raised when a Coach cannot be found."""
14class CoachAlreadyExistException(Exception):
15 """Raised when a Coach already exists."""
18class CoachRepository(ABC):
19 """An interface for a coach repository."""
21 @abstractmethod
22 def create_query(self) -> CoachQuery:
23 """Create a query for querying coaches."""
24 raise NotImplementedError
26 @abstractmethod
27 async def get_by_id(self, id_: ClubCoachIdentifier) -> ClubCoachEntity:
28 """Get a coach by its id."""
29 raise NotImplementedError
31 @abstractmethod
32 async def get(self, query: CoachQuery) -> ClubCoachEntity:
33 """Get the first coach matching the query.
35 Raises:
36 CoachNotFoundException: If no coach can be found.
37 """
38 raise NotImplementedError
40 @abstractmethod
41 def get_all(
42 self,
43 query: CoachQuery | None = None,
44 limit: int | None = None,
45 offset: int | None = None,
46 ) -> AsyncGenerator[ClubCoachEntity, None]:
47 """Get all coaches matching the query.
49 Args:
50 query: The query to use for selecting the coaches.
51 limit: The maximum number of entities to return.
52 offset: Skip the offset rows before beginning to return entities.
54 Yields:
55 Club coach entities.
56 """
58 @abstractmethod
59 async def create(self, coach: ClubCoachEntity):
60 """Save a new coach."""
61 raise NotImplementedError
63 @abstractmethod
64 async def delete(self, coach: ClubCoachEntity):
65 """Delete an existing coach."""
66 raise NotImplementedError
68 @abstractmethod
69 async def update(self, coach: ClubCoachEntity):
70 """Update an existing coach."""
71 raise NotImplementedError