Coverage for src/kwai/modules/portal/news/news_item.py: 100%
44 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 a news item entity."""
3from dataclasses import dataclass, field
5from kwai.core.domain.entity import Entity
6from kwai.core.domain.value_objects.identifier import IntIdentifier
7from kwai.core.domain.value_objects.period import Period
8from kwai.core.domain.value_objects.text import LocaleText
9from kwai.core.domain.value_objects.timestamp import Timestamp
10from kwai.core.domain.value_objects.traceable_time import TraceableTime
11from kwai.modules.portal.applications.application import ApplicationEntity
14NewsItemIdentifier = IntIdentifier
17@dataclass(frozen=True, kw_only=True, slots=True)
18class Promotion:
19 """Value object for handling promoted news items."""
21 priority: int = 0
22 end_date: Timestamp = field(default_factory=Timestamp)
25class NewsItemEntity(Entity[NewsItemIdentifier]):
26 """A news item entity."""
28 def __init__(
29 self,
30 *,
31 id_: NewsItemIdentifier | None = None,
32 enabled: bool = False,
33 promotion: Promotion = None,
34 period: Period = None,
35 application: ApplicationEntity,
36 texts: list[LocaleText],
37 remark: str = "",
38 traceable_time: TraceableTime | None = None,
39 ):
40 super().__init__(id_ or NewsItemIdentifier())
41 self._enabled = enabled
42 self._promotion = promotion or Promotion()
43 self._period = period or Period()
44 self._application = application
45 self._texts = texts
46 self._remark = remark
47 self._traceable_time = traceable_time or TraceableTime()
49 @property
50 def is_enabled(self) -> bool:
51 """Check if the news item is enabled."""
52 return self._enabled
54 @property
55 def promotion(self) -> Promotion:
56 """Return the promotion information of the news item."""
57 return self._promotion
59 @property
60 def period(self) -> Period:
61 """Return the active period of the news item."""
62 return self._period
64 @property
65 def remark(self) -> str:
66 """Return the remark."""
67 return self._remark
69 @property
70 def application(self) -> ApplicationEntity:
71 """Return the application."""
72 return self._application
74 @property
75 def texts(self) -> list[LocaleText]:
76 """Return the text content of the news item.
78 Remark:
79 The list is a copy
80 """
81 return self._texts.copy()
83 @property
84 def traceable_time(self) -> TraceableTime:
85 """Return the creation/modification timestamp of this application."""
86 return self._traceable_time