-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
61 lines (50 loc) · 1.56 KB
/
api.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
from typing import Union
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from fastapi.encoders import jsonable_encoder
from base.db_base import TableData
from db import PostgreSQL
app = FastAPI()
@app.get("/")
def read_root():
obj = dict()
obj["Hello"] = "World"
return JSONResponse(content=obj)
@app.get("/get_user_list")
def read_user_list():
db = PostgreSQL()
return JSONResponse(content=db.get_user_list())
@app.get("/get_user/{id}")
def read_user(id: int):
db = PostgreSQL()
#user_table_desc = db.get_user_table_desk()
user_list = db.get_user_table_where_id(id)
res = {}
if user_list != None:
user_list = list(user_list)
if len(user_list) > 0:
#for num in range(len(user_table_desc)):
#res[user_table_desc[num]] = user_list[0][num]
return JSONResponse(content=user_list[0])
return JSONResponse(content={})
@app.get("/get_user_table")
def read_user_table():
db = PostgreSQL()
user_list = db.get_user_table()
return JSONResponse(content=user_list)
@app.get("/get_table_list")
def read_user_table():
db = PostgreSQL()
user_list = db.get_table_list()
return JSONResponse(content=user_list)
@app.get("/get_user_desc")
def read_user_table():
db = PostgreSQL()
data = db.get_table_structure_data("TestTable")
return JSONResponse(content=data)
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
obj = dict()
obj["item_id"] = item_id
obj["q"] = q
return JSONResponse(content=obj)