File size: 1,200 Bytes
2f88c81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# why schemas? it is a way to define the structure of the data sent to the server and the data received from the server
from pydantic import BaseModel, Field
import datetime as dt

# template for user data. this is used to validate the data sent to the server


class userBase(BaseModel):
    first_name: str = Field(...)
    last_name: str = Field(...)
    email: str = Field(...,)


class userCreate(userBase):
    password: str = Field(...)  # hashed password

    class Config:
        orm_mode = True  # to tell pydantic to read the data even if it is not a dict but an ORM model
        schema_extra = {
            "example": {
                "first_name": "John",
                "last_name": "Doe",
                "email": "[email protected]",
                "password": "password",
            }
        }


class User(userBase):
    user_id: int

    class Config:
        orm_mode = True


class TodoBase(BaseModel):
    task_name: str
    task_description: str
    priority: int
    category: str
    due_date: dt.date
    status: bool = False


class TodoCreate(TodoBase):
    pass


class Todo(TodoBase):
    todo_id: int
    user_id: int

    class Config:
        orm_mode = True