-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_models.py
101 lines (89 loc) · 2.24 KB
/
_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""
Models for Boxer
"""
from dataclasses import dataclass
from typing import Dict
@dataclass
class BoxerClaim:
"""
Boxer Claim
"""
claim_type: str
claim_value: str
issuer: str
def to_dict(self) -> Dict:
""" Convert to Dictionary
:return: Dictionary
"""
return {
"claimType": self.claim_type,
"claimValue": self.claim_value,
"issuer": self.issuer
}
@classmethod
def from_dict(cls, json_data: Dict):
""" Initialize from Dictionary
:param json_data: Dictionary
:return:
"""
return BoxerClaim(
claim_type=json_data['claimType'],
claim_value=json_data['claimValue'],
issuer=json_data['issuer']
)
@dataclass
class UserClaim:
"""
Boxer User Claim
"""
user_id: str
user_claim_id: str
claim: BoxerClaim
def to_dict(self) -> Dict:
""" Convert to Dictionary
:return: Dictionary
"""
return {
"userId": self.user_id,
"userClaimId": self.user_claim_id,
"claim": self.claim.to_dict()
}
@classmethod
def from_dict(cls, json_data: Dict):
""" Initialize from Dictionary
:param json_data: Dictionary
:return:
"""
return UserClaim(
user_id=json_data['userId'],
user_claim_id=json_data['userClaimId'],
claim=BoxerClaim.from_dict(json_data['claim'])
)
@dataclass
class GroupClaim:
"""
Boxer Group Claim
"""
group_name: str
group_claim_id: str
claim: BoxerClaim
def to_dict(self) -> Dict:
""" Convert to Dictionary
:return: Dictionary
"""
return {
"groupName": self.group_name,
"groupClaimId": self.group_claim_id,
"claim": self.claim.to_dict()
}
@classmethod
def from_dict(cls, json_data: Dict):
""" Initialize from Dictionary
:param json_data: Dictionary
:return:
"""
return GroupClaim(
group_name=json_data['groupName'],
group_claim_id=json_data['groupClaimId'],
claim=BoxerClaim.from_dict(json_data['claim'])
)