-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (28 loc) · 889 Bytes
/
main.py
File metadata and controls
36 lines (28 loc) · 889 Bytes
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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
app = FastAPI()
#allow frontend to fetch data from the backend
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # need to change this to my domian once in prod
allow_credintals=True,
allow_methods=["*"],
allow_headers=["*"],
)
# sample court data
pickleball_courts = [
{"lat": 37.7749, "lng": -122.4194}, # San Francisco
{"lat": 34.0522, "lng": -118.2437}, # Los Angeles
]
# define request model
class Court(BaseModel):
lat: float
lng: float
@app.get("/api/courts")
def get_courts():
return pickleball_courts
@app.post("/api/add_court")
def add_court(court:Court):
pickleball_courts.append({"lat":court.lat, "lng":court.lng})
return{"message": "Court was successfully added!", "lat":court.lat, "lng": court.lng}