Coverage for kwai/api/schemas/user_invitation.py: 100%

33 statements  

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

1"""Schemas for a user invitation resource.""" 

2 

3from kwai.core import json_api 

4from kwai.modules.identity.user_invitations.user_invitation import UserInvitationEntity 

5 

6 

7@json_api.resource(type_="user_invitations") 

8class UserInvitationResource: 

9 """Represent a JSON:API resource for a user invitation.""" 

10 

11 def __init__(self, invitation: UserInvitationEntity): 

12 self._invitation = invitation 

13 

14 @json_api.id 

15 def get_id(self) -> str: 

16 """Get the id of the user invitation.""" 

17 return str(self._invitation.uuid) 

18 

19 @json_api.attribute(name="email") 

20 def get_email(self) -> str: 

21 """Get the email address for the invitation.""" 

22 return str(self._invitation.email) 

23 

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

25 def get_first_name(self) -> str: 

26 """Get the first name of the receiver.""" 

27 return self._invitation.name.first_name 

28 

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

30 def get_last_name(self) -> str: 

31 """Get the last name of the receiver.""" 

32 return self._invitation.name.last_name 

33 

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

35 def get_remark(self) -> str: 

36 """Get a remark about the invitation.""" 

37 return self._invitation.remark 

38 

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

40 def get_expired_at(self) -> str | None: 

41 """Get the timestamp of expiration.""" 

42 return str(self._invitation.expired_at) 

43 

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

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

46 """Get the timestamp of confirmation.""" 

47 return str(self._invitation.confirmed_at) 

48 

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

50 def get_created_at(self) -> str | None: 

51 """Get the timestamp of creation.""" 

52 return str(self._invitation.traceable_time.created_at) 

53 

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

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

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

57 return str(self._invitation.traceable_time.updated_at)