|
|
@@ -1,6 +1,6 @@
|
|
|
import time
|
|
|
from datetime import datetime
|
|
|
-from fastapi import FastAPI,Form,Request
|
|
|
+from fastapi import FastAPI, Form, Request
|
|
|
from fastapi.templating import Jinja2Templates
|
|
|
from pydantic import BaseModel
|
|
|
import os, dataset, json
|
|
|
@@ -9,32 +9,20 @@ 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):
|
|
|
+async def read_root(request: Request):
|
|
|
return templates.TemplateResponse("index.html",{"request": request})
|
|
|
|
|
|
-'''@app.post("/submitform")
|
|
|
-def formentry(booking: booking_info):
|
|
|
- db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
|
|
|
+@app.post("/submitform")
|
|
|
+async def formentry(name: str = Form(...), phone: str = Form(...), loc: str = Form(...), course_name: str = Form(...), bookdate: str = Form(...), booktime: str = Form(...)):
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/violetbeauty?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(...)):
|
|
|
+ print(time_stamp)
|
|
|
|
|
|
- #reserved space for uploading to database
|
|
|
+ request_table.insert({"name": name, "phone": phone, "location": loc, "course_name":course_name, "book_date": bookdate, "book_time": booktime, "time_stamp": time_stamp})
|
|
|
|
|
|
- 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
|
|
|
+ return 0 # pls make booking success page
|
|
|
+ # return templates.TemplateResponse("(bookingsuccess.html)",{"request": request})
|