Coverage for kwai/modules/news/stories/story.py: 100%
55 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 a story entity."""
2from dataclasses import dataclass, field
4from kwai.core.domain.entity import Entity
5from kwai.core.domain.value_objects.identifier import IntIdentifier
6from kwai.core.domain.value_objects.local_timestamp import LocalTimestamp
7from kwai.core.domain.value_objects.name import Name
8from kwai.core.domain.value_objects.period import Period
9from kwai.core.domain.value_objects.text import LocaleText
10from kwai.core.domain.value_objects.traceable_time import TraceableTime
11from kwai.core.domain.value_objects.unique_id import UniqueId
13StoryIdentifier = IntIdentifier
16@dataclass(frozen=True, kw_only=True, slots=True)
17class Promotion:
18 """Value object for handling promoted news stories."""
20 priority: int = 0
21 end_date: LocalTimestamp = field(default_factory=LocalTimestamp)
24@dataclass(frozen=True, kw_only=True, slots=True)
25class Application:
26 """Value object for an application."""
28 id: IntIdentifier
29 name: str
30 title: str
33@dataclass(frozen=True, kw_only=True, slots=True)
34class Author:
35 """Value object for an author of content."""
37 id: IntIdentifier
38 uuid: UniqueId
39 name: Name
42class StoryEntity(Entity[StoryIdentifier]):
43 """A story entity."""
45 def __init__(
46 self,
47 *,
48 id_: StoryIdentifier | None = None,
49 enabled: bool = False,
50 promotion: Promotion = None,
51 period: Period = None,
52 application: Application,
53 content: list[LocaleText],
54 remark: str = "",
55 traceable_time: TraceableTime | None = None,
56 ):
57 super().__init__(id_ or StoryIdentifier())
58 self._enabled = enabled
59 self._promotion = promotion or Promotion()
60 self._period = period or Period()
61 self._application = application
62 self._content = content
63 self._remark = remark
64 self._traceable_time = traceable_time or TraceableTime()
66 @property
67 def is_enabled(self) -> bool:
68 """Check if the story is enabled."""
69 return self._enabled
71 @property
72 def promotion(self) -> Promotion:
73 """Return the promotion information of the story."""
74 return self._promotion
76 @property
77 def period(self) -> Period:
78 """Return the active period of the story."""
79 return self._period
81 @property
82 def remark(self) -> str:
83 """Return the remark."""
84 return self._remark
86 @property
87 def application(self) -> Application:
88 """Return the application."""
89 return self._application
91 @property
92 def content(self) -> list[LocaleText]:
93 """Return the contents of the story.
95 Remark:
96 The list is a copy
97 """
98 return self._content.copy()
100 @property
101 def traceable_time(self) -> TraceableTime:
102 """Return the creation/modification timestamp of this application."""
103 return self._traceable_time