-
Notifications
You must be signed in to change notification settings - Fork 0
48 lines (35 loc) · 1.08 KB
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
from fastapi import FastAPI
from pymongo import MongoClient
from pydantic import BaseModel
class Reservation(BaseModel):
name : str
time: int
table_number: int
client = MongoClient('mongodb://localhost', 27017)
# TODO fill in database name
db = client["afternoon-assign"]
# TODO fill in collection name
collection = db["table"]
app = FastAPI()
# TODO complete all endpoint.
@app.get("/reservation/by-name/{name}")
def get_reservation_by_name(name:str):
result = collection.find({"name" : name})
for r in result:
print(r)
print("\n")
@app.get("reservation/by-table/{table}")
def get_reservation_by_table(table: int):
result = collection.find({"table" : table},{"_id": 0, "name": 1,"table":0,"hour":1})
for r in result:
print(r)
print("\n")
@app.post("/reservation")
def reserve(reservation : Reservation):
pass
@app.put("/reservation/update/")
def update_reservation(reservation: Reservation):
pass
@app.delete("/reservation/delete/{name}/{table_number}")
def cancel_reservation(name: str, table_number : int):
pass