Coverage for bc/kwai-bc-identity/src/kwai_bc_identity/enact_user.py: 100%
16 statements
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.11.0, 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
8from kwai_bc_identity.users.user_account import UserAccountEntity
9from kwai_bc_identity.users.user_account_repository import UserAccountRepository
12@dataclass(frozen=True, kw_only=True, slots=True)
13class EnactUserCommand:
14 """Input for the EnactUser use case.
16 Attributes:
17 uuid: The UUID of the user to enact.
18 """
20 uuid: str
23class EnactUser:
24 """Use case for enacting a user."""
26 def __init__(
27 self,
28 repo: UserAccountRepository,
29 presenter: Presenter[UserAccountEntity],
30 ):
31 """Initialize the use case.
33 Args:
34 repo: The user account repository to use.
35 presenter: The presenter that will be used to return the user.
36 """
37 self._repo = repo
38 self._presenter = presenter
40 async def execute(self, command: EnactUserCommand) -> None:
41 """Execute the use case.
43 Raises:
44 UserAccountNotFoundException: If the user does not exist.
45 """
46 user_account = await self._repo.get_user_by_uuid(
47 UniqueId.create_from_string(command.uuid)
48 )
49 user_account = user_account.enact()
50 await self._repo.update(user_account)
51 self._presenter.present(user_account)