From 820b29529b425a0f8f40e735465368dc311a1a85 Mon Sep 17 00:00:00 2001 From: Hanzo_dev <2002samudiojohan@gmail.com> Date: Sun, 22 Feb 2026 10:46:52 -0500 Subject: [PATCH] Fix: Standardized Taxi API types and response models for Postgres compatibility --- backend/app/api/taxis/__init__.py | 46 +++++++++++++++++-------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/backend/app/api/taxis/__init__.py b/backend/app/api/taxis/__init__.py index 8b2639a..99268db 100644 --- a/backend/app/api/taxis/__init__.py +++ b/backend/app/api/taxis/__init__.py @@ -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) ):