From 921aaa3fae59378606ec377298eb6d3687d0cb65 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Fri, 28 Mar 2025 14:45:01 +0000 Subject: [PATCH] Update code in endpoints/routeoptimization.get.py --- endpoints/routeoptimization.get.py | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/endpoints/routeoptimization.get.py b/endpoints/routeoptimization.get.py index e69de29..582ea27 100644 --- a/endpoints/routeoptimization.get.py +++ b/endpoints/routeoptimization.get.py @@ -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 \ No newline at end of file