Coverage for kwai/api/v1/trainings/schemas/training_definition.py: 66%

41 statements  

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

1"""Module for the training definition schema.""" 

2from kwai.core import json_api 

3from kwai.modules.training.trainings.training_definition import TrainingDefinitionEntity 

4 

5 

6@json_api.resource(type_="training_definitions") 

7class TrainingDefinitionResource: 

8 """JSON:API resource for a training definition.""" 

9 

10 def __init__(self, training_definition: TrainingDefinitionEntity): 

11 """Initialize a training definition resource. 

12 

13 Args: 

14 training_definition: the training definition entity that is 

15 transformed to a JSON:API resource. 

16 """ 

17 self._training_definition = training_definition 

18 

19 @json_api.id 

20 def get_id(self) -> str: 

21 """Return the id of the training definition.""" 

22 return str(self._training_definition.id) 

23 

24 @json_api.attribute(name="name") 

25 def get_name(self) -> str: 

26 """Get the name of the training definition.""" 

27 return self._training_definition.name 

28 

29 @json_api.attribute(name="description") 

30 def get_description(self) -> str: 

31 """Get the description of the training definition.""" 

32 return self._training_definition.description 

33 

34 @json_api.attribute(name="weekday") 

35 def get_weekday(self) -> int: 

36 """Get the week day of the training definition.""" 

37 return self._training_definition.weekday.value 

38 

39 @json_api.attribute(name="start_time") 

40 def get_start_time(self) -> str: 

41 """Get the start time of the training definition.""" 

42 return str(self._training_definition.period.start) 

43 

44 @json_api.attribute(name="end_time") 

45 def get_end_time(self) -> str | None: 

46 """Get the end time of the training definition.""" 

47 if self._training_definition.period.end: 

48 return str(self._training_definition.period.end) 

49 return None 

50 

51 @json_api.attribute(name="active") 

52 def get_active(self) -> bool: 

53 """Get if the training definition is active.""" 

54 return self._training_definition.active 

55 

56 @json_api.attribute(name="location") 

57 def get_location(self) -> str: 

58 """Get the location of the training definition.""" 

59 return self._training_definition.location 

60 

61 @json_api.attribute(name="remark") 

62 def get_remark(self) -> str: 

63 """Get the remark of the training definition.""" 

64 return self._training_definition.remark 

65 

66 @json_api.attribute(name="created_at") 

67 def get_created_at(self) -> str: 

68 """Get the timestamp of creation.""" 

69 return str(self._training_definition.traceable_time.created_at) 

70 

71 @json_api.attribute(name="updated_at") 

72 def get_updated_at(self) -> str | None: 

73 """Get the timestamp of the last update.""" 

74 return str(self._training_definition.traceable_time.updated_at)