-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschemas.py
134 lines (99 loc) · 2.97 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
from pydantic import BaseModel, Field, validator
from typing import Optional, List
import re
from datetime import datetime
import models
# for validating an Email
regex = "^(\w|\.|\_|\-)+[@](\w|\_|\-|\.)+[.]\w{2,4}$"
class User(BaseModel):
first_name: str
last_name: str
nickname: str
email: str
subscribed: Optional[bool]
@validator("email")
def validate_email(cls, value):
re.search(regex, value)
if re.search(regex, value):
return value
raise ValueError("Invalid email")
class Config:
orm_mode = True
class CreateUser(User):
password: str
@validator("password")
def validate_password(cls, value):
if re.fullmatch(
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*#?&.,])[A-Za-z\d@.,$!#%*?&]{6,20}$",
value,
):
return value
raise ValueError("Password is too easy or contains inappropriate symbols")
class RequestResult(BaseModel):
result: str = Field(description='"success" or "error"')
error_description: Optional[str] = Field(description="In case of error")
success_description: Optional[str] = Field(
description="Sometimes in case of success"
)
class ChangingTypeUser(BaseModel):
identifier: str = Field(description="email or nickname")
class UserForSearchAnswer(BaseModel):
id: Optional[int]
first_name: Optional[str]
last_name: Optional[str]
nickname: Optional[str]
email: Optional[str]
account_image: Optional[str]
subscribed: Optional[bool]
type: Optional[models.UserType]
class Config:
orm_mode = True
class UserForSearchRequest(UserForSearchAnswer):
type: Optional[List[models.UserType]]
offset: Optional[int] = 0
count: Optional[int] = 15
class SelfInfoAnswer(UserForSearchAnswer):
type: Optional[models.UserType]
class LoginResult(RequestResult):
id: Optional[int]
username: Optional[int]
class ArticleForAdd(BaseModel):
image: str
header: str
content: str
class SearchArticle(BaseModel):
id: Optional[int]
header: Optional[str] = ""
content: Optional[str] = ""
author_id: Optional[int]
status: List[models.ModerationStatus] = [models.ModerationStatus.published]
offset: Optional[int] = 0
count: Optional[int] = 15
class Article(BaseModel):
id: int
image: str
header: str
content: str
creation_date: Optional[datetime]
publication_date: Optional[datetime]
author_id: int
status: models.ModerationStatus
class Config:
orm_mode = True
class AddComment(BaseModel):
reply_id: Optional[int]
content: str
article_id: int
class Comment(BaseModel):
id: int
reply_id: Optional[int]
content: str
creation_date: datetime
status: models.ModerationStatus
author_id: int
article_id: int
replies: Optional[List["Comment"]]
author_object: Optional[UserForSearchAnswer]
class Config:
orm_mode = True
Comment.update_forward_refs()