12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- from enum import Enum
- from typing import Optional
- from pydantic import BaseModel
- from fastapi import FastAPI, Query, UploadFile, File
- import dataset,json
- from fastapi import FastAPI
- from fastapi.middleware.cors import CORSMiddleware
- app = FastAPI()
- origins = [
- "https://hhh.com.tw"
- "http://172.105.205.52",
- "http://172.105.205.52:800020",
- ]
- app.add_middleware(
- CORSMiddleware,
- allow_origins=origins,
- allow_credentials=True,
- allow_methods=["*"],
- allow_headers=["*"],
- )
- db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
- class deco_request(BaseModel):
- id: int
- name: str
- email: str
- phone: str
- #detail
- loc: str
- h_class: str
- type: str
- budget: str
- size: float
- bed_num: int
- liv_num: int
- bath_num: int
- style: str
- prefer_date: str
-
- @app.get("/deco_request")
- async def get_tags():
- request_table = db['deco_request']
- statement = 'SELECT * FROM deco_request'
- reqs = []
- for req in db.query(statement):
- reqs.append({'name':req.name,'email':req.email,'phone':req.phone,'loc':req.loc
- ,'h_class':req.h_class,'type':req.type,'budget':req.budget,'size':req.size,'bed_num':req.bed_num
- ,'liv_num':req.liv_num,'bath_num':req.bath_num,'style':req.style,'prefer_date':req.prefer_date})
- return reqs
- @app.post("/deco_request")
- async def create_tags(req:deco_request):
- request_table = db['deco_request']
- pk = request_table.insert({'name':req.name,'email':req.email,'phone':req.phone,'loc':req.loc
- ,'h_class':req.h_class,'type':req.type,'budget':req.budget,'size':req.size,'bed_num':req.bed_num
- ,'liv_num':req.liv_num,'bath_num':req.bath_num,'style':req.style,'prefer_date':req.prefer_date})
- req.id = pk
- return req
-
-
-
-
|