Coverage for bc/kwai-bc-club/src/kwai_bc_club/domain/value_objects.py: 93%
30 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 for defining value objects for the members module."""
3from dataclasses import dataclass
4from enum import Enum
6from kwai_core.domain.value_objects.date import Date
7from kwai_core.domain.value_objects.unique_id import UniqueId
9from kwai_bc_club.domain.country import CountryEntity
12@dataclass(kw_only=True, frozen=True, slots=True)
13class License:
14 """A license of a member."""
16 number: str
17 end_date: Date
19 @property
20 def expired(self):
21 """Is this license expired?"""
22 return self.end_date.past
24 def __str__(self) -> str:
25 """Return a string representation of a license."""
26 return self.number
29class Gender(Enum):
30 """The gender of a person."""
32 UNKNOWN = 0
33 MALE = 1
34 FEMALE = 2
37@dataclass(frozen=True, slots=True)
38class Birthdate:
39 """A birthdate of a person."""
41 date: Date
43 @property
44 def age(self) -> int:
45 """Return the age on the current day."""
46 return self.date.get_age(self.date.today())
48 def get_age_in_year(self, year: int) -> int:
49 """Return the age that will be reached in the given year."""
50 date = Date.create(year, 12, 31)
51 return self.date.get_age(date)
53 def __str__(self) -> str:
54 """Return a string representation of a birthdate."""
55 return str(self.date)
58@dataclass(kw_only=True, frozen=True, slots=True)
59class Address:
60 """An address."""
62 address: str
63 postal_code: str
64 city: str
65 county: str
66 country: CountryEntity
69@dataclass(kw_only=True, frozen=True, slots=True)
70class User:
71 """A user."""
73 id: int
74 uuid: UniqueId