Coverage for bc/kwai-bc-club/src/kwai_bc_club/domain/value_objects.py: 94%
31 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.name import Name
8from kwai_core.domain.value_objects.unique_id import UniqueId
10from kwai_bc_club.domain.country import CountryEntity
13@dataclass(kw_only=True, frozen=True, slots=True)
14class License:
15 """A license of a member."""
17 number: str
18 end_date: Date
20 @property
21 def expired(self):
22 """Is this license expired?"""
23 return self.end_date.past
25 def __str__(self) -> str:
26 """Return a string representation of a license."""
27 return self.number
30class Gender(Enum):
31 """The gender of a person."""
33 UNKNOWN = 0
34 MALE = 1
35 FEMALE = 2
38@dataclass(frozen=True, slots=True)
39class Birthdate:
40 """A birthdate of a person."""
42 date: Date
44 @property
45 def age(self) -> int:
46 """Return the age on the current day."""
47 return self.date.get_age(self.date.today())
49 def get_age_in_year(self, year: int) -> int:
50 """Return the age that will be reached in the given year."""
51 date = Date.create(year, 12, 31)
52 return self.date.get_age(date)
54 def __str__(self) -> str:
55 """Return a string representation of a birthdate."""
56 return str(self.date)
59@dataclass(kw_only=True, frozen=True, slots=True)
60class Address:
61 """An address."""
63 address: str
64 postal_code: str
65 city: str
66 county: str
67 country: CountryEntity
70@dataclass(kw_only=True, frozen=True, slots=True)
71class User:
72 """A user."""
74 id: int
75 uuid: UniqueId
76 name: Name