-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschemas.py
executable file
·139 lines (115 loc) · 3.29 KB
/
schemas.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/python3
from marshmallow import Schema, fields
"""Define the schemas for the models
PlainItemSchema: Plain Item Schema
PlainStoreSchema: Plain Store Schema
PlainTagSchema: Plain Tag Schema
ItemUpdateSchema: Item Update Schema
ItemSchema: Item Schema inherit from PlainItemSchema
StoreSchema: Store Schema inherit from PlainStoreSchema
TagSchema: Tag Schema inherit from PlainTagSchema
TagAndItemSchema: Tag and Item Schema
UserSchema: User Schema"""
class PlainItemSchema(Schema):
"""
Plain Item Schema
Attributes:
id: Item id
name: Item name
price: Item price
"""
id = fields.Int(dump_only=True)
name = fields.Str(required=True)
price = fields.Float(required=True)
class PlainStoreSchema(Schema):
"""
Plain Store Schema
Attributes:
id: Store id
name: Store name
"""
id = fields.Int(dump_only=True)
name = fields.Str(required=True)
class PlainTagSchema(Schema):
"""
Plain Tag Schema
Attributes:
id: Tag id
name: Tag name
"""
id = fields.Int(dump_only=True)
name = fields.Str()
class ItemUpdateSchema(Schema):
"""
Item Update Schema
Attributes:
name: Item name
price: Item price
"""
name = fields.Str()
price = fields.Float()
class ItemSchema(PlainItemSchema):
"""
Item Schema inherit from PlainItemSchema
Attributes:
store_id: Store id
store: Store object
"""
store_id = fields.Int(required=True, load_only=True)
store = fields.Nested(PlainStoreSchema(), dump_only=True)
class StoreSchema(PlainStoreSchema):
"""
Store Schema inherit from PlainStoreSchema
Attributes:
items: List of items
tags: List of tags
"""
items = fields.List(fields.Nested(PlainItemSchema()), dump_only=True)
tags = fields.List(fields.Nested(PlainTagSchema()), dump_only=True)
class StoreUpdateSchema(Schema):
"""
Store Update Schema
Attributes:
name: Store name
"""
name = fields.Str()
class TagSchema(PlainTagSchema):
"""
Tag Schema inherit from PlainTagSchema
Attributes:
store_id: Store id
store: Store object
items: List of items
"""
store_id = fields.Int(load_only=True)
store = fields.Nested(PlainStoreSchema(), dump_only=True)
items = fields.List(fields.Nested(PlainItemSchema()), dump_only=True)
class TagAndItemSchema(Schema):
"""
Tag and Item Schema
Attributes:
message: Message
item: Item object
tag: Tag object
"""
message = fields.Str()
item = fields.Nested(ItemSchema)
tag = fields.Nested(TagSchema)
# class PlainUserSchema(Schema):
# """Docs: To be updated """
# id = fields.Int(dump_only=True)
# username = fields.Str(required=True)
# password = fields.Str(required=True, load_only=True)
# class UserSchema(PlainUserSchema):
# id = fields.Int(load_only=True)
# users = fields.List(fields.Nested(PlainUserSchema), dump_only=True)
class UserSchema(Schema):
"""User Schema
Attributes:
id: User id
username: User username
password: User password
"""
id = fields.Int(dump_only=True)
username = fields.Str(required=True)
password = fields.Str(required=True)