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