-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
38 lines (29 loc) · 1.31 KB
/
test.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
from fastapi import FastAPI
from pydantic import BaseModel
class Item(BaseModel):
user_id: str
name: str
group: str
app = FastAPI()
User_list =[
{"id":"001","uid":"Mingjia01","email":"[email protected]","credit":101.00,"orders":[{"id":"001","mid":"A01","startTime":"starttime","startTime":"endtime","expired":False}]},
{"id":"002","uid":"Mingjia02","email":"[email protected]","credit":102.00,"orders":[{"id":"002","mid":"A02","startTime":"starttime","startTime":"endtime","expired":True}]}
# {"user_id":"M002","name":"Hanako","group":"A"},
# {"user_id":"M003","name":"Hiroshi","group":"B"},
# {"user_id":"M004","name":"Kyoko","group":"B"},
]
#curl http://localhost:8000/user/allUsers/
@app.get("/user/allUsers/")
async def users():
res = dict(users = User_list)
return res
#curl http://localhost:8000/Users/{user_id}
@app.get("/Users/{uid}")
async def users(u_user_id:str):
return list(filter(lambda item : item['user_id']==uid, User_list))
#curl -X POST -H "accept: application/json" -H "Content-Type: application/json" -d "{\"user_id\":\"M005\", \"Name\":\"Aya\", \"group\":\"C\"}," http://localhost:8000/Users/
@app.post("/user/addUser")
async def users(user: Item):
User_list.append({"user_id": user.user_id,"name":user.name,"group":user.group})
res = dict(users = User_list)
return res