Coverage for src/kwai/modules/identity/enact_user.py: 100%
17 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 for enacting a user."""
3from dataclasses import dataclass
5from kwai.core.domain.presenter import Presenter
6from kwai.core.domain.value_objects.unique_id import UniqueId
7from kwai.modules.identity.users.user_account import UserAccountEntity
8from kwai.modules.identity.users.user_account_repository import UserAccountRepository
11@dataclass(frozen=True, kw_only=True, slots=True)
12class EnactUserCommand:
13 """Input for the EnactUser use case.
15 Attributes:
16 uuid: The UUID of the user to enact.
17 """
19 uuid: str
22class EnactUser:
23 """Use case for enacting a user."""
25 def __init__(
26 self,
27 repo: UserAccountRepository,
28 presenter: Presenter[UserAccountEntity],
29 ):
30 """Initialize the use case.
32 Args:
33 repo: The user account repository to use.
34 presenter: The presenter that will be used to return the user.
35 """
36 self._repo = repo
37 self._presenter = presenter
39 async def execute(self, command: EnactUserCommand) -> None:
40 """Execute the use case.
42 Raises:
43 UserAccountNotFoundException: If the user does not exist.
44 """
45 user_account = await self._repo.get_user_by_uuid(
46 UniqueId.create_from_string(command.uuid)
47 )
48 user_account = user_account.enact()
49 await self._repo.update(user_account)
50 self._presenter.present(user_account)