-
Notifications
You must be signed in to change notification settings - Fork 0
/
schemas.py
66 lines (51 loc) · 2.42 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
from marshmallow import Schema, fields, validate
class PlainBookSchema(Schema):
link_id = fields.Str(dump_only=True)
title = fields.Str(required=True)
added_at = fields.Str(dump_only=True)
release_year = fields.Int(validate=lambda x: x > 0)
completed = fields.Int(validate=validate.OneOf([0,1]), load_default=False)
bookmarked = fields.Int(validate=validate.OneOf([0,1]), load_default=False)
active = fields.Int(validate=validate.OneOf([0,1]), load_default=False)
file_url = fields.URL(dump_only=True)
mime_type = fields.Str(dump_only=True)
class PlainTagSchema(Schema):
link_id = fields.Str(dump_only=True)
tag = fields.Str(required=True)
class TagSchema(PlainTagSchema):
books = fields.List(fields.Nested(PlainBookSchema()), dump_only=True)
class TagUpdateSchema(Schema):
tag = fields.Str()
class BookSchema(PlainBookSchema):
tags = fields.List(fields.Nested(PlainTagSchema()), dump_only=True)
class BookUpdateSchema(Schema):
title = fields.Str()
release_year = fields.Int(validate=lambda x: x > 0)
completed = fields.Int(validate=validate.OneOf([0,1]))
bookmarked = fields.Int(validate=validate.OneOf([0,1]))
active = fields.Int(validate=validate.OneOf([0,1]))
class PlainUserSchema(Schema):
link_id = fields.Str(dump_only=True)
user_name = fields.Str(required=True)
email = fields.Email(required=True, validate=validate.Email())
is_admin = fields.Int(validate=validate.OneOf([0,1]), load_default=False)
class UserRegisterSchema(PlainUserSchema):
user_password = fields.Str(required=True, load_only=True)
#access_code = fields.Str(required=True, load_only=True)
class UserUpdateSchema(Schema):
email = fields.Email(required=True, validate=validate.Email())
user_password = fields.Str(required=True, load_only=True)
class UserLoginSchema(Schema):
user_name = fields.Str(required=True)
user_password = fields.Str(required=True, load_only=True)
class MultipartFileSchema(Schema):
file = fields.Raw(required=True, metadata={"type": "file"})
class BookSearchQueryArgs(Schema):
title = fields.Str(required=False)
release_year = fields.Int(required=False)
sort = fields.Str(required=False)
order = fields.Str(required=False)
class TagSearchQueryArgs(Schema):
name = fields.Str(required=False)
class UserSearchQueryArgs(Schema):
name = fields.Str(required=False)