Coverage for bc/kwai-bc-portal/src/kwai_bc_portal/repositories/author_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 that defines an interface for an Author repository."""
3from abc import ABC, abstractmethod
4from typing import AsyncGenerator
6from kwai_core.domain.value_objects.unique_id import UniqueId
8from kwai_bc_portal.domain.author import AuthorEntity, AuthorIdentifier
9from kwai_bc_portal.repositories.author_query import AuthorQuery
12class AuthorNotFoundException(Exception):
13 """Raised when an author cannot be found."""
16class AuthorRepository(ABC):
17 """An interface for an author repository."""
19 @abstractmethod
20 def create_query(self) -> AuthorQuery:
21 """Create a query for quering authors."""
22 raise NotImplementedError
24 @abstractmethod
25 async def get(self, id: AuthorIdentifier) -> AuthorEntity:
26 """Get the author with the given user identifier."""
27 raise NotImplementedError
29 @abstractmethod
30 async def get_by_uuid(self, uuid: UniqueId) -> AuthorEntity:
31 """Get the author that is linked to the user with the given uuid."""
32 raise NotImplementedError
34 @abstractmethod
35 def get_all(
36 self, query: AuthorQuery | None = None, limit: int = 0, offset: int = 0
37 ) -> AsyncGenerator[AuthorEntity, None]:
38 """Yield all authors of a given query.
40 Args:
41 query: The query to use for selecting the authors.
42 limit: The maximum number of entities to return.
43 offset: Skip the offset rows before beginning to return entities.
44 """
45 raise NotImplementedError
47 @abstractmethod
48 async def create(self, author: AuthorEntity) -> AuthorEntity:
49 """Save an author entity to the database."""
50 raise NotImplementedError
52 @abstractmethod
53 async def delete(self, author: AuthorEntity) -> None:
54 """Delete an author entity from the dabase."""
55 raise NotImplementedError