diff --git a/endpoints/dispatch.post.py b/endpoints/dispatch.post.py index e69de29..3badd2b 100644 --- a/endpoints/dispatch.post.py +++ b/endpoints/dispatch.post.py @@ -0,0 +1,23 @@ +from fastapi import APIRouter, Depends, HTTPException, status +from sqlalchemy.orm import Session +from typing import List +from core.database import get_db +from models.ride import Ride +from schemas.ride import RideSchema, RideCreate +from helpers.ride_helpers import get_all_rides, create_ride, dispatch_ride + +router = APIRouter() + +@router.post("/dispatch", status_code=status.HTTP_201_CREATED, response_model=RideSchema) +async def dispatch_new_ride( + ride: RideCreate, + db: Session = Depends(get_db) +): + """Dispatch a new ride""" + new_ride = create_ride(db=db, ride=ride) + if not new_ride: + raise HTTPException(status_code=400, detail="Ride could not be created") + dispatched_ride = dispatch_ride(db=db, ride=new_ride) + if not dispatched_ride: + raise HTTPException(status_code=400, detail="Ride could not be dispatched") + return dispatched_ride \ No newline at end of file