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 def get_all(
33 self,
34 query: CoachQuery | None = None,
35 limit: int | None = None,
36 offset: int | None = None,
37 ) -> AsyncGenerator[ClubCoachEntity, None]:
38 """Get all coaches matching the query.
40 Args:
41 query: The query to use for selecting the coaches.
42 limit: The maximum number of entities to return.
43 offset: Skip the offset rows before beginning to return entities.
45 Yields:
46 Club coach entities.
47 """
49 @abstractmethod
50 async def create(self, coach: ClubCoachEntity):
51 """Save a new coach."""
52 raise NotImplementedError
54 @abstractmethod
55 async def delete(self, coach: ClubCoachEntity):
56 """Delete an existing coach."""
57 raise NotImplementedError
59 @abstractmethod
60 async def update(self, coach: ClubCoachEntity):
61 """Update an existing coach."""
62 raise NotImplementedError