Coverage for src/kwai/modules/portal/news/news_item_repository.py: 100%
6 statements
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
1"""Module that defines an interface for a news item repository."""
3from abc import ABC, abstractmethod
4from typing import AsyncIterator
6from kwai.modules.portal.news.news_item import NewsItemEntity, NewsItemIdentifier
7from kwai.modules.portal.news.news_item_query import NewsItemQuery
10class NewsItemNotFoundException(Exception):
11 """Raised when the news item can not be found."""
14class NewsItemRepository(ABC):
15 """Interface for a news item repository."""
17 @abstractmethod
18 async def create(self, news_item: NewsItemEntity) -> NewsItemEntity:
19 """Create a new news item entity.
21 Args:
22 news_item: The news item to create
24 Returns:
25 The news item entity with an identifier.
26 """
27 raise NotImplementedError
29 @abstractmethod
30 async def update(self, news_item: NewsItemEntity):
31 """Update a news item entity.
33 Args:
34 news_item: The news item to update.
35 """
36 raise NotImplementedError
38 @abstractmethod
39 async def delete(self, news_item: NewsItemEntity):
40 """Delete a news item.
42 Args:
43 news_item: The news item to delete.
44 """
45 raise NotImplementedError
47 @abstractmethod
48 def create_query(self) -> NewsItemQuery:
49 """Create a query for querying news items."""
50 raise NotImplementedError
52 @abstractmethod
53 async def get_by_id(self, id_: NewsItemIdentifier) -> NewsItemEntity:
54 """Get the news item with the given id.
56 Args:
57 id_: The id of the news item.
59 Returns:
60 A news item entity.
61 """
62 raise NotImplementedError
64 @abstractmethod
65 async def get_all(
66 self,
67 query: NewsItemQuery | None = None,
68 limit: int | None = None,
69 offset: int | None = None,
70 ) -> AsyncIterator[NewsItemEntity]:
71 """Return all news items of a given query.
73 Args:
74 query: The query to use for selecting the rows.
75 limit: The maximum number of entities to return.
76 offset: Skip the offset rows before beginning to return entities.
78 Yields:
79 A list of news items.
80 """
81 raise NotImplementedError