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

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.unique_id import UniqueId 

8 

9from kwai_bc_club.domain.country import CountryEntity 

10 

11 

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

13class License: 

14 """A license of a member.""" 

15 

16 number: str 

17 end_date: Date 

18 

19 @property 

20 def expired(self): 

21 """Is this license expired?""" 

22 return self.end_date.past 

23 

24 def __str__(self) -> str: 

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

26 return self.number 

27 

28 

29class Gender(Enum): 

30 """The gender of a person.""" 

31 

32 UNKNOWN = 0 

33 MALE = 1 

34 FEMALE = 2 

35 

36 

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

38class Birthdate: 

39 """A birthdate of a person.""" 

40 

41 date: Date 

42 

43 @property 

44 def age(self) -> int: 

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

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

47 

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) 

52 

53 def __str__(self) -> str: 

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

55 return str(self.date) 

56 

57 

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

59class Address: 

60 """An address.""" 

61 

62 address: str 

63 postal_code: str 

64 city: str 

65 county: str 

66 country: CountryEntity 

67 

68 

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

70class User: 

71 """A user.""" 

72 

73 id: int 

74 uuid: UniqueId