Coverage for kwai/api/schemas/application.py: 69%

42 statements  

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

1"""Schemas for an application resource.""" 

2from kwai.core import json_api 

3from kwai.modules.portal.applications.application import ApplicationEntity 

4 

5 

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

7class ApplicationResource: 

8 """Represents a JSON:API resource for applications.""" 

9 

10 def __init__(self, application: ApplicationEntity): 

11 self._application = application 

12 

13 @json_api.id 

14 def get_id(self) -> str: 

15 """Get the id of the application.""" 

16 return str(self._application.id) 

17 

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

19 def get_name(self) -> str: 

20 """Get the name of the application.""" 

21 return self._application.name 

22 

23 @json_api.attribute(name="title") 

24 def get_title(self) -> str: 

25 """Get the title of the application.""" 

26 return self._application.title 

27 

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

29 def get_description(self) -> str: 

30 """Get the description of the application.""" 

31 return self._application.description 

32 

33 @json_api.attribute(name="short_description") 

34 def get_short_description(self) -> str: 

35 """Get the short description the application.""" 

36 return self._application.short_description 

37 

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

39 def get_remark(self) -> str: 

40 """Get the remark about the application.""" 

41 return self._application.remark 

42 

43 @json_api.attribute(name="news") 

44 def get_news(self) -> bool: 

45 """Check if this application can contain news stories.""" 

46 return self._application.can_contain_news 

47 

48 @json_api.attribute(name="pages") 

49 def get_pages(self) -> bool: 

50 """Check if this application can contain pages.""" 

51 return self._application.can_contain_pages 

52 

53 @json_api.attribute(name="events") 

54 def get_events(self) -> bool: 

55 """Check if this application can contain events.""" 

56 return self._application.can_contain_events 

57 

58 @json_api.attribute(name="weight") 

59 def get_weight(self) -> int: 

60 """Get the weight of the application.""" 

61 return self._application.weight 

62 

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

64 def get_created_at(self) -> str: 

65 """Get the timestamp of creation.""" 

66 return str(self._application.traceable_time.created_at) 

67 

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

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

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

71 return str(self._application.traceable_time.updated_at)