|
@@ -1,21 +1,40 @@
|
|
|
+import time
|
|
|
from datetime import datetime
|
|
|
from fastapi import FastAPI,Form,Request
|
|
|
from fastapi.templating import Jinja2Templates
|
|
|
-import os
|
|
|
+from pydantic import BaseModel
|
|
|
+import os, dataset, json
|
|
|
|
|
|
app = FastAPI()
|
|
|
directory=os.path.dirname(os.getcwd())
|
|
|
templates = Jinja2Templates(directory)
|
|
|
|
|
|
+class booking_info(BaseModel):
|
|
|
+ name:str
|
|
|
+ phone:str
|
|
|
+ loc:str
|
|
|
+ course_name:str
|
|
|
+ bookdate:str
|
|
|
+ booktime:str
|
|
|
+
|
|
|
@app.get("/")
|
|
|
def read_root(request: Request):
|
|
|
return templates.TemplateResponse("index.html",{"request": request})
|
|
|
|
|
|
-@app.post("/submitform")
|
|
|
-def formentry(name: str = Form(...), phone: str = Form(...), loc: str = Form(...), course_name: str = Form(...), date: str = Form(...), time: str = Form(...)):
|
|
|
+'''@app.post("/submitform")
|
|
|
+def formentry(booking: booking_info):
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
|
|
|
+ request_table = db['booking_info']
|
|
|
time_stamp = datetime.fromtimestamp(time.time())
|
|
|
time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
|
+ pk = request_table.insert(["name": booking.name, "phone": booking.phone, "loc": booking.loc, "course_name": booking.course_name, "date": booking.bookdate, "time": booking.booktime])
|
|
|
+ return pk
|
|
|
+'''
|
|
|
+
|
|
|
+@app.post("/submitform")
|
|
|
+def formentry(name: str = Form(...), phone: str = Form(...), loc: str = Form(...), course_name: str = Form(...), date: str = Form(...), time: str = Form(...)):
|
|
|
+
|
|
|
#reserved space for uploading to database
|
|
|
|
|
|
- return {"name": name, "phone": phone, "loc":loc, "course_name": course_name, "date": date, "time": time, "timestamp": datetime.fromtimestamp(time.time())} #currently using this, will be modified once we deal with uploading
|
|
|
+ return {"name": name, "phone": phone, "loc":loc, "course_name": course_name, "date": date, "time": time} #currently using this, will be modified once we deal with uploading
|