-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschemas.py
91 lines (61 loc) · 2.53 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
from marshmallow import Schema, fields
class PlainItemSchema(Schema):
id = fields.Int(dump_only=True)
title = fields.Str(required=True)
price = fields.Float(required=True)
inventory = fields.Int(required=True)
description = fields.Str(required=True)
class PlainStoreSchema(Schema):
id = fields.Int(dump_only=True)
name = fields.Str()
class PlainTagSchema(Schema):
id = fields.Int(dump_only=True)
name = fields.Str()
class ItemSchema(PlainItemSchema):
store_id = fields.Int(required=True, load_only=True)
store = fields.Nested(PlainStoreSchema(), dump_only=True)
tags = fields.List(fields.Nested(PlainTagSchema()), dump_only=True)
class ItemUpdateSchema(Schema):
name = fields.Str()
price = fields.Float()
class StoreSchema(PlainStoreSchema):
items = fields.List(fields.Nested(PlainItemSchema()), dump_only=True)
tags = fields.List(fields.Nested(PlainTagSchema()), dump_only=True)
class TagSchema(PlainTagSchema):
store_id = fields.Int(load_only=True)
items = fields.List(fields.Nested(PlainItemSchema()), dump_only=True)
store = fields.Nested(PlainStoreSchema(), dump_only=True)
class TagAndItemSchema(Schema):
message = fields.Str()
item = fields.Nested(ItemSchema)
tag = fields.Nested(TagSchema)
class UserSchema(Schema):
id = fields.Int(dump_only=True)
email = fields.Email(required=True)
password = fields.Str(required=True, load_only=True)
first_name = fields.Str(required=True)
last_name = fields.Str(required=True)
phone = fields.Str(required=True)
access = fields.Int(required=True)
class LoginSchema(Schema):
email = fields.Str(required=True)
password = fields.Str(required=True, load_only=True)
class CartItemSchema(Schema):
item_id = fields.Int(required=True)
quantity = fields.Int(required=True)
class CartSchema(Schema):
id = fields.Int(dump_only=True)
cart_items = fields.List(fields.Nested(CartItemSchema()), dump_only=True)
class CartUpdateSchema(Schema):
cart_items = fields.List(fields.Nested(CartItemSchema()))
class OrderItemSchema(Schema):
id = fields.Int(dump_only=True)
item_id = fields.Int(required=True)
quantity = fields.Int(required=True)
unit_price = fields.Float(dump_only=True)
class OrderSchema(Schema):
id = fields.Int(dump_only=True)
cart_id = fields.Int(required=True, load_only=True)
customer_id = fields.Int(dump_only=True)
created_at = fields.String(dump_only=True)
order_items = fields.List(fields.Nested(OrderItemSchema()), dump_only=True)