forked from SR-11-2021-10/Backend-SR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schemas.py
62 lines (47 loc) · 1.43 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
"""
Here, we are going to instanciate the schemas to help us
validate HTTP body request has an appropiate format.
"""
# Pydantic Base Schema
from pydantic import BaseModel
class UserBase(BaseModel):
"""
This class only includes the username attributes which is the common attributes
when we receive a POST to create a new one or GET an existing one.
"""
username: str
class UserAuth(UserBase):
"""
This schema allows us to parse the content off all client request including the password
"""
password: str
class User(UserBase):
"""
This is the schema we will use to response a request about an user information
Config subclass indicates pydantic to retrieve data from ORM models. Note that
we are not retriving the hashed_password field in the model to send in response.
This is the main reason we create 3 schemas
"""
# Now the User PK is the username
# For this reason, a id PK is not longer needed
# id: int
class Config:
orm_mode = True
class Recommendation(BaseModel):
"""
Request body to make a recommendation
Attributes
----------
type : str
Type of model to create and predict
similitude : str
Similitude measure to use
username : str
Username to make the recommendation
artist : str
Artist id to predict
"""
type: str
similitude: str
username: str
artist: str