Coverage for bc/kwai-bc-portal/src/kwai_bc_portal/domain/news_item.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2024-01-01 00:00 +0000

1"""Module that defines a news item entity.""" 

2 

3from dataclasses import dataclass, field 

4from typing import ClassVar, Type 

5 

6from kwai_core.domain.entity import DataclassEntity 

7from kwai_core.domain.value_objects.identifier import IntIdentifier 

8from kwai_core.domain.value_objects.period import Period 

9from kwai_core.domain.value_objects.text import LocaleText 

10from kwai_core.domain.value_objects.timestamp import Timestamp 

11from kwai_core.domain.value_objects.traceable_time import TraceableTime 

12 

13from kwai_bc_portal.domain.application import ApplicationEntity 

14 

15 

16@dataclass(frozen=True, kw_only=True, slots=True) 

17class Promotion: 

18 """Value object for handling promoted news items.""" 

19 

20 priority: int = 0 

21 end_date: Timestamp = field(default_factory=Timestamp) 

22 

23 

24class NewsItemIdentifier(IntIdentifier): 

25 """Identifier for a news item.""" 

26 

27 

28@dataclass(kw_only=True, eq=False, slots=True, frozen=True) 

29class NewsItemEntity(DataclassEntity): 

30 """A news item entity. 

31 

32 Attrs: 

33 enabled: Is this newsitem enabled? 

34 promotion: Should this newsitem be promoted? 

35 period: The period to display this newsitem. 

36 application: The application this newsitem belongs to. 

37 texts: The content of the newsitem. 

38 remark: A remark about this newsitem. 

39 traceable_time: When is this newsitem created and updated? 

40 """ 

41 

42 ID: ClassVar[Type] = NewsItemIdentifier 

43 

44 enabled: bool = False 

45 promotion: Promotion = field(default_factory=Promotion) 

46 period: Period = field(default_factory=Period) 

47 application: ApplicationEntity 

48 texts: tuple[LocaleText, ...] 

49 remark: str = "" 

50 traceable_time: TraceableTime = field(default_factory=TraceableTime)