Spaces:
Sleeping
Sleeping
Update garuda/api/router.py
Browse files- garuda/api/router.py +25 -15
garuda/api/router.py
CHANGED
|
@@ -46,30 +46,40 @@ def get_all_flights():
|
|
| 46 |
|
| 47 |
@router.get("/search")
|
| 48 |
def search_flights(
|
| 49 |
-
departure_date: date = Query(
|
| 50 |
-
origin: str = Query(
|
| 51 |
-
destination: str = Query(
|
| 52 |
):
|
| 53 |
results = []
|
| 54 |
|
| 55 |
for flight in flight_db:
|
| 56 |
-
flight_date = flight["departure_time"].date()
|
| 57 |
|
| 58 |
-
if
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
and flight["destination"].upper() == destination.upper()
|
| 62 |
-
):
|
| 63 |
-
results.append(flight)
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
return {
|
| 72 |
"total": len(results),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
"flights": results
|
| 74 |
}
|
| 75 |
|
|
|
|
| 46 |
|
| 47 |
@router.get("/search")
|
| 48 |
def search_flights(
|
| 49 |
+
departure_date: Optional[date] = Query(None),
|
| 50 |
+
origin: Optional[str] = Query(None),
|
| 51 |
+
destination: Optional[str] = Query(None)
|
| 52 |
):
|
| 53 |
results = []
|
| 54 |
|
| 55 |
for flight in flight_db:
|
|
|
|
| 56 |
|
| 57 |
+
if departure_date:
|
| 58 |
+
if flight["departure_time"].date() != departure_date:
|
| 59 |
+
continue
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
if origin:
|
| 62 |
+
if flight["origin"].upper() != origin.upper():
|
| 63 |
+
continue
|
| 64 |
+
|
| 65 |
+
if destination:
|
| 66 |
+
if flight["destination"].upper() != destination.upper():
|
| 67 |
+
continue
|
| 68 |
+
|
| 69 |
+
results.append(flight)
|
| 70 |
+
|
| 71 |
+
# stop at top 15
|
| 72 |
+
if len(results) == 15:
|
| 73 |
+
break
|
| 74 |
|
| 75 |
return {
|
| 76 |
"total": len(results),
|
| 77 |
+
"limit": 15,
|
| 78 |
+
"filters": {
|
| 79 |
+
"departure_date": departure_date,
|
| 80 |
+
"origin": origin,
|
| 81 |
+
"destination": destination
|
| 82 |
+
},
|
| 83 |
"flights": results
|
| 84 |
}
|
| 85 |
|