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

1"""Module for defining value objects for the members module.""" 

2 

3from dataclasses import dataclass 

4from enum import Enum 

5 

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 

9 

10from kwai_bc_club.domain.country import CountryEntity 

11 

12 

13@dataclass(kw_only=True, frozen=True, slots=True) 

14class License: 

15 """A license of a member.""" 

16 

17 number: str 

18 end_date: Date 

19 

20 @property 

21 def expired(self): 

22 """Is this license expired?""" 

23 return self.end_date.past 

24 

25 def __str__(self) -> str: 

26 """Return a string representation of a license.""" 

27 return self.number 

28 

29 

30class Gender(Enum): 

31 """The gender of a person.""" 

32 

33 UNKNOWN = 0 

34 MALE = 1 

35 FEMALE = 2 

36 

37 

38@dataclass(frozen=True, slots=True) 

39class Birthdate: 

40 """A birthdate of a person.""" 

41 

42 date: Date 

43 

44 @property 

45 def age(self) -> int: 

46 """Return the age on the current day.""" 

47 return self.date.get_age(self.date.today()) 

48 

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) 

53 

54 def __str__(self) -> str: 

55 """Return a string representation of a birthdate.""" 

56 return str(self.date) 

57 

58 

59@dataclass(kw_only=True, frozen=True, slots=True) 

60class Address: 

61 """An address.""" 

62 

63 address: str 

64 postal_code: str 

65 city: str 

66 county: str 

67 country: CountryEntity 

68 

69 

70@dataclass(kw_only=True, frozen=True, slots=True) 

71class User: 

72 """A user.""" 

73 

74 id: int 

75 uuid: UniqueId 

76 name: Name