Fix: Standardized Taxi API types and response models for Postgres compatibility
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
from fastapi import APIRouter, Depends, Query, HTTPException, UploadFile, File, Form
|
||||
from sqlmodel import Session, select
|
||||
from typing import Optional
|
||||
import os
|
||||
import shutil
|
||||
from uuid import uuid4
|
||||
from uuid import uuid4, UUID
|
||||
from typing import List
|
||||
from app.core.database import get_session
|
||||
from app.models.taxi import Taxi
|
||||
from app.api.deps import get_current_admin
|
||||
@ -13,7 +13,7 @@ router = APIRouter(prefix="/api/taxis", tags=["taxis"])
|
||||
UPLOAD_DIR = "uploads"
|
||||
|
||||
|
||||
@router.get("")
|
||||
@router.get("", response_model=List[Taxi])
|
||||
async def get_taxis(
|
||||
corregimiento: Optional[str] = Query(None),
|
||||
shift: Optional[str] = Query(None),
|
||||
@ -22,22 +22,26 @@ async def get_taxis(
|
||||
session: Session = Depends(get_session)
|
||||
):
|
||||
"""Get all taxis with optional filters."""
|
||||
statement = select(Taxi)
|
||||
|
||||
if is_active is not None:
|
||||
statement = statement.where(Taxi.is_active == is_active)
|
||||
|
||||
if corregimiento:
|
||||
statement = statement.where(Taxi.corregimiento.contains(corregimiento))
|
||||
|
||||
if shift:
|
||||
statement = statement.where(Taxi.shift == shift)
|
||||
|
||||
if english_speaking is not None:
|
||||
statement = statement.where(Taxi.english_speaking == english_speaking)
|
||||
try:
|
||||
statement = select(Taxi)
|
||||
|
||||
taxis = session.exec(statement).all()
|
||||
return taxis
|
||||
if is_active is not None:
|
||||
statement = statement.where(Taxi.is_active == is_active)
|
||||
|
||||
if corregimiento:
|
||||
statement = statement.where(Taxi.corregimiento.contains(corregimiento))
|
||||
|
||||
if shift:
|
||||
statement = statement.where(Taxi.shift == shift)
|
||||
|
||||
if english_speaking is not None:
|
||||
statement = statement.where(Taxi.english_speaking == english_speaking)
|
||||
|
||||
taxis = session.exec(statement).all()
|
||||
return taxis
|
||||
except Exception as e:
|
||||
print(f"Error fetching taxis: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.post("")
|
||||
@ -83,9 +87,9 @@ async def create_taxi(
|
||||
return taxi
|
||||
|
||||
|
||||
@router.put("/{taxi_id}")
|
||||
@router.put("/{taxi_id}", response_model=Taxi)
|
||||
async def update_taxi(
|
||||
taxi_id: str,
|
||||
taxi_id: UUID,
|
||||
owner_name: str = Form(...),
|
||||
phone_number: str = Form(...),
|
||||
license_plate: str = Form(...),
|
||||
@ -132,7 +136,7 @@ async def update_taxi(
|
||||
|
||||
@router.delete("/{taxi_id}")
|
||||
async def delete_taxi(
|
||||
taxi_id: str,
|
||||
taxi_id: UUID,
|
||||
session: Session = Depends(get_session),
|
||||
_: bool = Depends(get_current_admin)
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user