Coverage for kwai/modules/identity/users/user.py: 97%
32 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
1"""Module that implements a User entity."""
3from kwai.core.domain.entity import Entity
4from kwai.core.domain.value_objects.email_address import EmailAddress
5from kwai.core.domain.value_objects.identifier import IntIdentifier
6from kwai.core.domain.value_objects.name import Name
7from kwai.core.domain.value_objects.traceable_time import TraceableTime
8from kwai.core.domain.value_objects.unique_id import UniqueId
10UserIdentifier = IntIdentifier
13class UserEntity(Entity[UserIdentifier]):
14 """A user entity."""
16 def __init__(
17 self,
18 *,
19 id_: UserIdentifier | None = None,
20 name: Name,
21 email: EmailAddress,
22 remark: str | None = "",
23 uuid: UniqueId | None = None,
24 traceable_time: TraceableTime | None = None,
25 ):
26 super().__init__(id_ or UserIdentifier())
27 self._name = name
28 self._email = email
29 self._uuid = uuid or UniqueId.generate()
30 self._remark = remark
31 self._traceable_time = traceable_time or TraceableTime()
33 @property
34 def email(self) -> EmailAddress:
35 """Return the email address of the user."""
36 return self._email
38 @property
39 def name(self) -> Name:
40 """Return the name of the user."""
41 return self._name
43 def mark_for_update(self):
44 """Mark the user as updated."""
45 self._traceable_time = self._traceable_time.mark_for_update()
47 @property
48 def remark(self) -> str:
49 """Return the remark for the user."""
50 return self._remark
52 @property
53 def traceable_time(self) -> TraceableTime:
54 """Return the creation/modification timestamp of the user."""
55 return self._traceable_time
57 @property
58 def uuid(self) -> UniqueId:
59 """Return the unique id the user."""
60 return self._uuid