Coverage for src/kwai/modules/portal/get_news_item.py: 100%
11 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 the use case "Get News Item"."""
3from dataclasses import dataclass
5from kwai.modules.portal.news.news_item import NewsItemEntity, NewsItemIdentifier
6from kwai.modules.portal.news.news_item_repository import NewsItemRepository
9@dataclass(kw_only=True, frozen=True, slots=True)
10class GetNewsItemCommand:
11 """Input for the use case "Get News Item"."""
13 id: int
16class GetNewsItem:
17 """Use case "Get News Item"."""
19 def __init__(self, repo: NewsItemRepository):
20 """Initialize the use case.
22 Args:
23 repo: A repository for getting the news item.
24 """
25 self._repo = repo
27 async def execute(self, command: GetNewsItemCommand) -> NewsItemEntity:
28 """Executes the use case.
30 Args:
31 command: The input for this use case.
33 Returns: A news item entity.
35 Raises:
36 NewsItemNotFoundException: When the news item does not exist.
37 """
38 return await self._repo.get_by_id(NewsItemIdentifier(command.id))