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

1"""Module for defining an interface for a news item query.""" 

2 

3from abc import abstractmethod 

4 

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 

8 

9 

10class NewsItemQuery(Query): 

11 """An interface for a news item query.""" 

12 

13 @abstractmethod 

14 def filter_by_id(self, id_: NewsItemIdentifier) -> "NewsItemQuery": 

15 """Add a filter on the news item id. 

16 

17 Args: 

18 id_: an id of a news item. 

19 """ 

20 raise NotImplementedError 

21 

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. 

27 

28 Args: 

29 year: Only return news items published in this year. 

30 month: Only return news items published in this month. 

31 

32 When month is omitted, all news items published in the given year will be 

33 returned. 

34 """ 

35 raise NotImplementedError 

36 

37 @abstractmethod 

38 def filter_by_promoted(self) -> "NewsItemQuery": 

39 """Add a filter to return only the promoted news items.""" 

40 raise NotImplementedError 

41 

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. 

45 

46 Args: 

47 application: The id or the name of the application 

48 """ 

49 raise NotImplementedError 

50 

51 @abstractmethod 

52 def filter_by_active(self) -> "NewsItemQuery": 

53 """Add a filter to only return active news items. 

54 

55 An active news item is enabled and is not expired. 

56 """ 

57 raise NotImplementedError 

58 

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. 

62 

63 Args: 

64 user: The id or unique id of the user. 

65 """ 

66 raise NotImplementedError 

67 

68 @abstractmethod 

69 def order_by_publication_date(self) -> "NewsItemQuery": 

70 """Order the result on the publication date.""" 

71 raise NotImplementedError