Coverage for kwai/modules/news/stories/story_repository.py: 100%
6 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
1"""Module that defines an interface for a story repository."""
2from abc import ABC, abstractmethod
3from typing import AsyncIterator
5from kwai.modules.news.stories.story import StoryEntity, StoryIdentifier
6from kwai.modules.news.stories.story_query import StoryQuery
9class StoryNotFoundException(Exception):
10 """Raised when the story can not be found."""
13class StoryRepository(ABC):
14 """Interface for a story repository."""
16 @abstractmethod
17 async def create(self, story: StoryEntity) -> StoryEntity:
18 """Create a new story entity.
20 Args:
21 story: The story to create
23 Returns:
24 The story entity with an identifier.
25 """
26 raise NotImplementedError
28 @abstractmethod
29 async def update(self, story: StoryEntity):
30 """Update a story entity.
32 Args:
33 story: The story to update.
34 """
35 raise NotImplementedError
37 @abstractmethod
38 async def delete(self, story: StoryEntity):
39 """Delete a story.
41 Args:
42 story: The story to delete.
43 """
44 raise NotImplementedError
46 @abstractmethod
47 def create_query(self) -> StoryQuery:
48 """Create a query for querying stories."""
49 raise NotImplementedError
51 @abstractmethod
52 async def get_by_id(self, id_: StoryIdentifier) -> StoryEntity:
53 """Get the story with the given id.
55 Args:
56 id_: The id of the story.
58 Returns:
59 A story entity.
60 """
61 raise NotImplementedError
63 @abstractmethod
64 async def get_all(
65 self,
66 query: StoryQuery | None = None,
67 limit: int | None = None,
68 offset: int | None = None,
69 ) -> AsyncIterator[StoryEntity]:
70 """Return all stories of a given query.
72 Args:
73 query: The query to use for selecting the rows.
74 limit: The maximum number of entities to return.
75 offset: Skip the offset rows before beginning to return entities.
77 Yields:
78 A list of stories.
79 """
80 raise NotImplementedError