Coverage for src/kwai/modules/club/domain/value_objects.py: 94%
35 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 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.modules.club.domain.country import CountryEntity
10@dataclass(kw_only=True, frozen=True, slots=True)
11class License:
12 """A license of a member."""
14 number: str
15 end_date: Date
17 @property
18 def expired(self):
19 """Is this license expired?"""
20 return self.end_date.past
22 def __str__(self) -> str:
23 """Return a string representation of a license."""
24 return self.number
27class Gender(Enum):
28 """The gender of a person."""
30 UNKNOWN = 0
31 MALE = 1
32 FEMALE = 2
35@dataclass(frozen=True, slots=True)
36class Birthdate:
37 """A birthdate of a person."""
39 date: Date
41 @property
42 def age(self) -> int:
43 """Return the age on the current day."""
44 return self.date.get_age(self.date.today())
46 def get_age_in_year(self, year: int) -> int:
47 """Return the age that will be reached in the given year."""
48 date = Date.create(year, 12, 31)
49 return self.date.get_age(date)
51 def __str__(self) -> str:
52 """Return a string representation of a birthdate."""
53 return str(self.date)
56@dataclass(kw_only=True, frozen=True, slots=True)
57class Address:
58 """An address."""
60 address: str
61 postal_code: str
62 city: str
63 county: str
64 country: CountryEntity