Coverage for src/kwai/modules/portal/update_application.py: 100%
24 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 the use case: update an application."""
3from dataclasses import dataclass
5from kwai.core.domain.entity import Entity
6from kwai.core.domain.value_objects.identifier import IntIdentifier
7from kwai.modules.portal.applications.application import ApplicationEntity
8from kwai.modules.portal.applications.application_repository import (
9 ApplicationRepository,
10)
13@dataclass(kw_only=True, frozen=True, slots=True)
14class UpdateApplicationCommand:
15 """Input for the use case [UpdateApplication][kwai.modules.portal.update_application.UpdateApplication].
17 Attributes:
18 id: The id of the application
19 """
21 id: int
22 title: str
23 short_description: str
24 description: str
25 remark: str
26 weight: int
27 events: bool
28 pages: bool
29 news: bool
32class UpdateApplication:
33 """Implements the use case 'update an application'."""
35 def __init__(self, application_repo: ApplicationRepository):
36 """Initialize the use case.
38 Args:
39 application_repo: A repository for updating an application.
40 """
41 self._application_repo = application_repo
43 async def execute(self, command: UpdateApplicationCommand) -> ApplicationEntity:
44 """Execute the use case.
46 Args:
47 command: The input for this use case.
48 """
49 application = await self._application_repo.get_by_id(IntIdentifier(command.id))
50 updated_application = Entity.replace(
51 application,
52 title=command.title,
53 short_description=command.short_description,
54 description=command.description,
55 remark=command.remark,
56 events=command.events,
57 pages=command.pages,
58 news=command.news,
59 weight=command.weight,
60 )
61 await self._application_repo.update(updated_application)
62 return updated_application