Coverage for src/kwai/modules/portal/repositories/author_repository.py: 100%
7 statements
« prev ^ index » next coverage.py v7.8.0, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.8.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
7from kwai.modules.portal.domain.author import AuthorEntity, AuthorIdentifier
8from kwai.modules.portal.repositories.author_query import AuthorQuery
11class AuthorNotFoundException(Exception):
12 """Raised when an author cannot be found."""
15class AuthorRepository(ABC):
16 """An interface for an author repository."""
18 @abstractmethod
19 def create_query(self) -> AuthorQuery:
20 """Create a query for quering authors."""
21 raise NotImplementedError
23 @abstractmethod
24 async def get(self, id: AuthorIdentifier) -> AuthorEntity:
25 """Get the author with the given user identifier."""
26 raise NotImplementedError
28 @abstractmethod
29 async def get_by_uuid(self, uuid: UniqueId) -> AuthorEntity:
30 """Get the author that is linked to the user with the given uuid."""
31 raise NotImplementedError
33 @abstractmethod
34 def get_all(
35 self, query: AuthorQuery | None = None, limit: int = 0, offset: int = 0
36 ) -> AsyncGenerator[AuthorEntity, None]:
37 """Yield all authors of a given query.
39 Args:
40 query: The query to use for selecting the authors.
41 limit: The maximum number of entities to return.
42 offset: Skip the offset rows before beginning to return entities.
43 """
44 raise NotImplementedError
46 @abstractmethod
47 async def create(self, author: AuthorEntity) -> AuthorEntity:
48 """Save an author entity to the database."""
49 raise NotImplementedError
51 @abstractmethod
52 async def delete(self, author: AuthorEntity) -> None:
53 """Delete an author entity from the dabase."""
54 raise NotImplementedError