feat: Add POST /dispatch endpoint
This commit is contained in:
parent
981e1faab9
commit
72c3ec2b19
@ -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
|
Loading…
x
Reference in New Issue
Block a user