fix: critical bug fixes - routes UUID, image paths, favorites loading, bottom nav debounce
This commit is contained in:
@ -8,11 +8,10 @@ from app.core.database import get_session
|
||||
from app.models.taxi import Taxi
|
||||
from app.api.deps import get_current_admin
|
||||
|
||||
from app.services.image_handler import save_image, delete_image
|
||||
|
||||
router = APIRouter(prefix="/api/taxis", tags=["taxis"])
|
||||
|
||||
UPLOAD_DIR = "uploads"
|
||||
|
||||
|
||||
@router.get("", response_model=List[Taxi])
|
||||
async def get_taxis(
|
||||
corregimiento: Optional[str] = Query(None),
|
||||
@ -62,12 +61,7 @@ async def create_taxi(
|
||||
"""Create a new taxi entry (Admin only)."""
|
||||
image_url = None
|
||||
if image:
|
||||
ext = os.path.splitext(image.filename)[1]
|
||||
filename = f"{uuid4()}{ext}"
|
||||
path = os.path.join(UPLOAD_DIR, "profiles", filename)
|
||||
with open(path, "wb") as buffer:
|
||||
shutil.copyfileobj(image.file, buffer)
|
||||
image_url = f"/uploads/profiles/{filename}"
|
||||
image_url = save_image(image, "profiles")
|
||||
|
||||
taxi = Taxi(
|
||||
owner_name=owner_name,
|
||||
@ -121,12 +115,9 @@ async def update_taxi(
|
||||
|
||||
# Handle image upload
|
||||
if image:
|
||||
ext = os.path.splitext(image.filename)[1]
|
||||
filename = f"{uuid4()}{ext}"
|
||||
path = os.path.join(UPLOAD_DIR, "profiles", filename)
|
||||
with open(path, "wb") as buffer:
|
||||
shutil.copyfileobj(image.file, buffer)
|
||||
db_taxi.image_url = f"/uploads/profiles/{filename}"
|
||||
if db_taxi.image_url:
|
||||
delete_image(db_taxi.image_url)
|
||||
db_taxi.image_url = save_image(image, "profiles")
|
||||
|
||||
session.add(db_taxi)
|
||||
session.commit()
|
||||
@ -144,6 +135,10 @@ async def delete_taxi(
|
||||
db_taxi = session.get(Taxi, taxi_id)
|
||||
if not db_taxi:
|
||||
raise HTTPException(status_code=404, detail="Taxi not found")
|
||||
|
||||
if db_taxi.image_url:
|
||||
delete_image(db_taxi.image_url)
|
||||
|
||||
session.delete(db_taxi)
|
||||
session.commit()
|
||||
return {"ok": True}
|
||||
|
||||
Reference in New Issue
Block a user