diff --git a/endpoints/routeoptimization.post.py b/endpoints/routeoptimization.post.py index e69de29..33fdd6a 100644 --- a/endpoints/routeoptimization.post.py +++ b/endpoints/routeoptimization.post.py @@ -0,0 +1,19 @@ +from fastapi import APIRouter, Depends +from sqlalchemy.orm import Session +from core.database import get_db +from schemas.route import RouteSchema, RouteCreate +from helpers.route_helpers import create_route, validate_unique_route + +router = APIRouter() + +@router.post("/routeoptimization", status_code=201, response_model=RouteSchema) +async def optimize_route( + route_data: RouteCreate, + db: Session = Depends(get_db) +): + if not validate_unique_route(db, route_data): + # Handle duplicate route error + return {"error": "Route with the same name or path already exists."} + + new_route = create_route(db, route_data) + return new_route \ No newline at end of file