35 lines
906 B
Python
35 lines
906 B
Python
from fastapi import APIRouter, HTTPException
|
|
|
|
routes = [] # In-memory storage
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/routeoptimization")
|
|
async def optimize_route(
|
|
start_point: str = "origin",
|
|
end_point: str = "destination",
|
|
waypoints: list = []
|
|
):
|
|
"""Demo route optimization endpoint"""
|
|
if not start_point or not end_point:
|
|
raise HTTPException(status_code=400, detail="Invalid route parameters")
|
|
|
|
route_id = len(routes) + 1
|
|
optimized_route = {
|
|
"id": route_id,
|
|
"start": start_point,
|
|
"end": end_point,
|
|
"waypoints": waypoints,
|
|
"disabled": False
|
|
}
|
|
routes.append(optimized_route)
|
|
|
|
return {
|
|
"message": "Route optimized successfully",
|
|
"route_id": route_id,
|
|
"path": [start_point] + waypoints + [end_point],
|
|
"features": {
|
|
"distance": 100,
|
|
"duration": 3600
|
|
}
|
|
} |