fix: critical bug fixes - routes UUID, image paths, favorites loading, bottom nav debounce

This commit is contained in:
2026-02-25 16:29:13 -05:00
parent c449083171
commit fd95df461b
14 changed files with 379 additions and 116 deletions

View File

@ -8,9 +8,9 @@ from app.core.database import get_session
from app.models.shuttle import Shuttle
from app.api.deps import get_current_admin
router = APIRouter(prefix="/api/shuttles", tags=["shuttles"])
from app.services.image_handler import save_image, delete_image
UPLOAD_DIR = "uploads"
router = APIRouter(prefix="/api/shuttles", tags=["shuttles"])
@router.get("", response_model=List[Shuttle])
async def get_shuttles(
@ -63,12 +63,7 @@ async def create_shuttle(
"""Create a new shuttle trip (Admin only)."""
image_url = None
if image:
ext = os.path.splitext(image.filename)[1]
filename = f"{uuid4()}{ext}"
path = os.path.join(UPLOAD_DIR, "vehicles", filename)
with open(path, "wb") as buffer:
shutil.copyfileobj(image.file, buffer)
image_url = f"/uploads/vehicles/{filename}"
image_url = save_image(image, "vehicles")
shuttle = Shuttle(
route_name=route_name,
@ -137,12 +132,10 @@ async def update_shuttle(
db_shuttle.is_active = is_active
if image:
ext = os.path.splitext(image.filename)[1]
filename = f"{uuid4()}{ext}"
path = os.path.join(UPLOAD_DIR, "vehicles", filename)
with open(path, "wb") as buffer:
shutil.copyfileobj(image.file, buffer)
db_shuttle.image_url = f"/uploads/vehicles/{filename}"
# Delete old image if exists
if db_shuttle.image_url:
delete_image(db_shuttle.image_url)
db_shuttle.image_url = save_image(image, "vehicles")
session.add(db_shuttle)
session.commit()
@ -159,6 +152,11 @@ async def delete_shuttle(
db_shuttle = session.get(Shuttle, shuttle_id)
if not db_shuttle:
raise HTTPException(status_code=404, detail="Shuttle not found")
# Delete image from storage
if db_shuttle.image_url:
delete_image(db_shuttle.image_url)
session.delete(db_shuttle)
session.commit()
return {"ok": True}