fix: critical bug fixes - routes UUID, image paths, favorites loading, bottom nav debounce
This commit is contained in:
@ -4,6 +4,10 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
import os
|
||||
|
||||
# Absolute path for uploads directory (relative to this file: app/main.py -> backend/uploads)
|
||||
_BACKEND_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
UPLOAD_BASE = os.path.join(_BACKEND_DIR, "uploads")
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.database import init_db, engine
|
||||
from sqlmodel import Session, select
|
||||
@ -31,6 +35,8 @@ from alembic import command
|
||||
import random
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from app.services.image_handler import cleanup_expired_coupons
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# Run migrations
|
||||
@ -46,6 +52,13 @@ async def lifespan(app: FastAPI):
|
||||
except:
|
||||
pass
|
||||
|
||||
# Run cleanup of expired coupons
|
||||
try:
|
||||
with Session(engine) as session:
|
||||
cleanup_expired_coupons(session)
|
||||
except Exception as e:
|
||||
print(f"WARNING: Initial cleanup failed: {e}")
|
||||
|
||||
# Seed sample data if empty
|
||||
with Session(engine) as session:
|
||||
# 1. Taxis
|
||||
@ -96,7 +109,7 @@ async def lifespan(app: FastAPI):
|
||||
biz = Business(name=spot["name"], address=f"Sector {spot['area']}", phone="6000-0000", category="Area Turistica", area=spot["area"], latitude=spot["lat"], longitude=spot["lng"])
|
||||
session.add(biz)
|
||||
session.flush()
|
||||
coupon = Coupon(title=f"Oferta en {biz.name}", description=f"Descuento especial en {biz.name}", business_id=biz.id, business_name=biz.name, business_address=biz.address, business_phone=biz.phone, category=biz.category, discount_percentage=15, valid_from=datetime.now().isoformat(), valid_until=(datetime.now() + timedelta(days=30)).isoformat(), is_active=True)
|
||||
coupon = Coupon(title=f"Oferta en {biz.name}", description=f"Descuento especial en {biz.name}", business_id=biz.id, business_name=biz.name, business_address=biz.address, business_phone=biz.phone, category=biz.category, discount_percentage=15, valid_from=datetime.now(), valid_until=(datetime.now() + timedelta(days=30)), is_active=True)
|
||||
session.add(coupon)
|
||||
session.commit()
|
||||
yield
|
||||
@ -128,11 +141,11 @@ app.add_middleware(
|
||||
)
|
||||
|
||||
# Ensure upload directories exist
|
||||
for sub in ["profiles", "vehicles", "businesses"]:
|
||||
os.makedirs(os.path.join("uploads", sub), exist_ok=True)
|
||||
for sub in ["profiles", "vehicles", "businesses", "coupons"]:
|
||||
os.makedirs(os.path.join(UPLOAD_BASE, sub), exist_ok=True)
|
||||
|
||||
# Mount static files
|
||||
app.mount("/uploads", StaticFiles(directory="uploads"), name="uploads")
|
||||
app.mount("/uploads", StaticFiles(directory=UPLOAD_BASE), name="uploads")
|
||||
|
||||
# Include routers
|
||||
app.include_router(routes_router)
|
||||
|
||||
Reference in New Issue
Block a user