logistics-app-dccv8k/endpoints/dispatch.post.py
2025-04-09 19:40:57 +00:00

23 lines
880 B
Python

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