Update code in endpoints/routeoptimization.get.py
This commit is contained in:
parent
3e3de2845a
commit
921aaa3fae
@ -0,0 +1,31 @@
|
|||||||
|
# Entity: RouteOptimization
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
from typing import List
|
||||||
|
from core.database import get_db
|
||||||
|
from models.route_optimization import RouteOptimization
|
||||||
|
from schemas.route_optimization import RouteOptimizationSchema
|
||||||
|
from helpers.route_optimization_helpers import get_optimized_route
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.get("/routeoptimization", status_code=200, response_model=RouteOptimizationSchema)
|
||||||
|
async def get_route_optimization(
|
||||||
|
start_location: str,
|
||||||
|
end_location: str,
|
||||||
|
waypoints: List[str],
|
||||||
|
db: Session = Depends(get_db)
|
||||||
|
):
|
||||||
|
optimized_route = get_optimized_route(
|
||||||
|
db,
|
||||||
|
start_location=start_location,
|
||||||
|
end_location=end_location,
|
||||||
|
waypoints=waypoints
|
||||||
|
)
|
||||||
|
if not optimized_route:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
|
detail="Could not generate optimized route"
|
||||||
|
)
|
||||||
|
return optimized_route
|
Loading…
x
Reference in New Issue
Block a user