-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.py
144 lines (123 loc) · 3.94 KB
/
sample.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
135
136
137
138
139
140
141
142
143
144
import time
from typing import List, Union
from fastapi import FastAPI, HTTPException, Request, status
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
class CheckList(BaseModel):
name: str
description: Union[str, None] = None
parent_id: Union[int, None] = None
children: List[int] = []
app = FastAPI()
# app.add_middleware(HTTPSRedirectMiddleware)
origins = ["http://localhost", "http://localhost:8080"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
start_time = time.time()
response = await call_next(request)
process_time = time.time() - start_time
response.headers["X-Process-Time"] = str(process_time)
return response
my_check_lists = {
"travel": {
"documents": ["ticket", "accomodation", "id"],
"clothes": ["weather", "jacket"],
"activities": ["shoes", "socks", "gloves", "glasses", "windbreaker"],
"devices": ["phone", "watch", "charger", "keys"],
"maintainance": [
"tooth brusher",
"razor",
"foam",
"anti-mosquito",
"hankerchief",
],
"stuff": ["gift", "other people items", "give away"],
"off": ["echo", "hot water", "kitchen"],
"on": ["autofeeder", "monitoring"],
},
"coffee-workspace": {
"devices": ["laptop", "phone", "ear-phone", "watch"],
"clothes": ["casual", "formal"],
"stationeries": ["pen", "note"],
"utilities": [
"tissue",
"wet-tissue",
"eye-drop",
"mosquito repellent",
"cleaning gel",
],
"others": ["book"],
},
"decision-making": {
"logical-reasoning": {
"situation": "logical, reasoning, analysis, scientific",
"strategies": [
"getting more info/data",
"fat-tail effect awareness",
"flexible options",
],
},
"instinct": {
"situation": "quick, no data, type two decision",
"strategies": [
"push back",
"delay",
"run",
"redirect",
"engaging",
"clarifying",
],
},
"consulting": {
"situation": "complicated, complex, technical, unfarmiliar domain",
"strategies": [
"seek expert opinion",
"search online",
"forum",
"friend, family",
],
},
"future-look-back": {
"situation": "long term effect, type one, hard to revert, moral, ethical, visionary, discipline",
"strategies": [
"vocal declaration",
"public validation",
"lock committment",
],
},
"put-other-in-your-shoes": {
"situation": "need objective view, realistic self-assessment, self-evaluation, moral, ethical",
"strategies": [
"decision would you advise your children/love/friend to make",
"decision your enemy would make",
"decision wise people would make",
],
},
},
}
@app.get("/")
async def root():
return "live"
@app.get("/lists")
async def lists():
return my_check_lists
@app.get("/list/{list_id}")
async def get_list(list_id: str):
if list_id not in my_check_lists:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="item not found"
)
return my_check_lists[list_id]
@app.post("/list/", status_code=status.HTTP_201_CREATED)
async def create_list(alist: CheckList):
return alist
@app.put("/list/{list_id}")
async def update_list(list_id: str, alist: CheckList):
return alist