Coverage for src/kwai/modules/portal/news/news_item_query.py: 100%
5 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 for defining an interface for a news item query."""
3from abc import abstractmethod
5from kwai.core.domain.repository.query import Query
6from kwai.core.domain.value_objects.unique_id import UniqueId
7from kwai.modules.portal.news.news_item import NewsItemIdentifier
10class NewsItemQuery(Query):
11 """An interface for a news item query."""
13 @abstractmethod
14 def filter_by_id(self, id_: NewsItemIdentifier) -> "NewsItemQuery":
15 """Add a filter on the news item id.
17 Args:
18 id_: an id of a news item.
19 """
20 raise NotImplementedError
22 @abstractmethod
23 def filter_by_publication_date(
24 self, year: int, month: int | None = None
25 ) -> "NewsItemQuery":
26 """Add a filter on the publication date.
28 Args:
29 year: Only return news items published in this year.
30 month: Only return news items published in this month.
32 When month is omitted, all news items published in the given year will be
33 returned.
34 """
35 raise NotImplementedError
37 @abstractmethod
38 def filter_by_promoted(self) -> "NewsItemQuery":
39 """Add a filter to return only the promoted news items."""
40 raise NotImplementedError
42 @abstractmethod
43 def filter_by_application(self, application: int | str) -> "NewsItemQuery":
44 """Add a filter to return only news items for the given application.
46 Args:
47 application: The id or the name of the application
48 """
49 raise NotImplementedError
51 @abstractmethod
52 def filter_by_active(self) -> "NewsItemQuery":
53 """Add a filter to only return active news items.
55 An active news item is enabled and is not expired.
56 """
57 raise NotImplementedError
59 @abstractmethod
60 def filter_by_user(self, user: int | UniqueId) -> "NewsItemQuery":
61 """Add a filter to only return news items of the given user.
63 Args:
64 user: The id or unique id of the user.
65 """
66 raise NotImplementedError
68 @abstractmethod
69 def order_by_publication_date(self) -> "NewsItemQuery":
70 """Order the result on the publication date."""
71 raise NotImplementedError