Coverage for kwai/modules/training/coaches/coach_tables.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-09-05 17:55 +0000

1"""Module that defines all dataclasses for the tables containing coaches.""" 

2from dataclasses import dataclass 

3 

4from kwai.core.db.table import Table 

5from kwai.core.domain.value_objects.name import Name 

6from kwai.modules.training.coaches.coach import CoachEntity, CoachIdentifier 

7 

8 

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

10class PersonRow: 

11 """Represent a row of the persons table.""" 

12 

13 id: int 

14 lastname: str 

15 firstname: str 

16 

17 

18PersonsTable = Table("persons", PersonRow) 

19 

20 

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

22class CoachRow: 

23 """Represent a row of the coaches table.""" 

24 

25 id: int 

26 person_id: int 

27 active: int 

28 

29 def create_entity(self, person_row: PersonRow) -> CoachEntity: 

30 """Create a coach entity from this row.""" 

31 return CoachEntity( 

32 id_=CoachIdentifier(self.id), 

33 name=Name(first_name=person_row.firstname, last_name=person_row.lastname), 

34 active=self.active == 1, 

35 ) 

36 

37 

38CoachesTable = Table("coaches", CoachRow)