-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
46 lines (32 loc) · 921 Bytes
/
index.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
from fastapi import FastAPI
from models import UserModel
from serialize import UserOut, UserUpdate
app = FastAPI()
@app.get("/")
def index():
instance =UserModel.scan()
return list(instance)
@app.post("/")
def create(user:UserOut):
user = user.dict()
instance =UserModel()
instance.email = user['email']
instance.first_name = user['first_name']
instance.last_name = user['last_name']
instance.save()
return
@app.delete("/{email}")
def deletar(email:str):
#update_item('views', 1, action='add')
instance = UserModel.get(email)
instance.delete(UserModel.email==email)
return
@app.put("/{email}")
def update(email:str, user:UserUpdate):
user = user.dict()
instance = UserModel.get(email)
instance.update(actions=[
UserModel.first_name.set(user['first_name']),
UserModel.last_name.set(user['last_name'])
])
return