feat: per-site QR menu mode (order vs view-only) + editable branding
Adds a sysadmin-configurable toggle so sites can disable online ordering on the public QR menu until it's fully supported, plus editable tagline/hours and a header image (replacing the hardcoded "Our Menu" placeholder) — all previously hardcoded frontend strings. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import os
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from config import settings
|
||||
from database import engine, Base
|
||||
@@ -39,6 +41,13 @@ def _run_migrations():
|
||||
migrations = [
|
||||
# Per-site order counter for public_ref generation (e.g. "ORD-0042")
|
||||
"ALTER TABLE sites ADD COLUMN order_counter INTEGER NOT NULL DEFAULT 0",
|
||||
# QR menu branding/config
|
||||
"ALTER TABLE sites ADD COLUMN menu_mode VARCHAR NOT NULL DEFAULT 'order'",
|
||||
"ALTER TABLE sites ADD COLUMN menu_tagline_en VARCHAR",
|
||||
"ALTER TABLE sites ADD COLUMN menu_tagline_gr VARCHAR",
|
||||
"ALTER TABLE sites ADD COLUMN menu_hours_en VARCHAR",
|
||||
"ALTER TABLE sites ADD COLUMN menu_hours_gr VARCHAR",
|
||||
"ALTER TABLE sites ADD COLUMN menu_header_image_url VARCHAR",
|
||||
]
|
||||
for sql in migrations:
|
||||
try:
|
||||
@@ -74,6 +83,9 @@ app.include_router(orders_router.router, prefix="/api/orders", tags=
|
||||
app.include_router(manager_auth_router.router, prefix="/api/manager", tags=["manager"])
|
||||
app.include_router(remote_dashboard_router.router,prefix="/api/remote", tags=["remote"])
|
||||
|
||||
os.makedirs("/app/data/site_headers", exist_ok=True)
|
||||
app.mount("/static/site_headers", StaticFiles(directory="/app/data/site_headers"), name="site_headers")
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
def health():
|
||||
|
||||
@@ -23,3 +23,11 @@ class Site(Base):
|
||||
waiter_domain = Column(String, nullable=True)
|
||||
# Monotonically incrementing counter used to generate public_ref for online orders
|
||||
order_counter = Column(Integer, default=0, nullable=False)
|
||||
|
||||
# QR menu branding/config
|
||||
menu_mode = Column(String, nullable=False, default="order") # "order" | "view_only"
|
||||
menu_tagline_en = Column(String, nullable=True)
|
||||
menu_tagline_gr = Column(String, nullable=True)
|
||||
menu_hours_en = Column(String, nullable=True)
|
||||
menu_hours_gr = Column(String, nullable=True)
|
||||
menu_header_image_url = Column(String, nullable=True)
|
||||
|
||||
@@ -36,7 +36,15 @@ def get_menu(site_slug: str, db: Session = Depends(get_db)):
|
||||
raise HTTPException(status_code=404, detail="No menu published yet")
|
||||
|
||||
import json
|
||||
return json.loads(snapshot.snapshot_json)
|
||||
data = json.loads(snapshot.snapshot_json)
|
||||
data["menu_mode"] = site.menu_mode
|
||||
data["restaurant"] = {
|
||||
"name": site.name,
|
||||
"tagline": {"en": site.menu_tagline_en, "gr": site.menu_tagline_gr},
|
||||
"hours": {"en": site.menu_hours_en, "gr": site.menu_hours_gr},
|
||||
"headerImageUrl": site.menu_header_image_url,
|
||||
}
|
||||
return data
|
||||
|
||||
|
||||
# ── Internal (site API key) ───────────────────────────────────────────────────
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import os
|
||||
import secrets
|
||||
import uuid
|
||||
from passlib.context import CryptContext
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from fastapi import APIRouter, Depends, HTTPException, UploadFile, File, status
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from auth_utils import get_current_admin
|
||||
@@ -12,6 +13,8 @@ from schemas.site import SiteCreate, SiteUpdate, SiteOut, SiteCreatedOut, LockRe
|
||||
router = APIRouter()
|
||||
_pwd = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||
|
||||
HEADER_IMAGE_DIR = "/app/data/site_headers"
|
||||
|
||||
|
||||
@router.get("/", response_model=list[SiteOut])
|
||||
def list_sites(db: Session = Depends(get_db), _=Depends(get_current_admin)):
|
||||
@@ -50,6 +53,8 @@ def update_site(site_id: str, body: SiteUpdate, db: Session = Depends(get_db), _
|
||||
site = db.query(Site).filter(Site.site_id == site_id).first()
|
||||
if not site:
|
||||
raise HTTPException(status_code=404, detail="Site not found")
|
||||
if body.menu_mode is not None and body.menu_mode not in ("order", "view_only"):
|
||||
raise HTTPException(status_code=400, detail="menu_mode must be 'order' or 'view_only'")
|
||||
for field, value in body.model_dump(exclude_none=True).items():
|
||||
setattr(site, field, value)
|
||||
db.commit()
|
||||
@@ -57,6 +62,51 @@ def update_site(site_id: str, body: SiteUpdate, db: Session = Depends(get_db), _
|
||||
return site
|
||||
|
||||
|
||||
@router.post("/{site_id}/header-image", response_model=SiteOut)
|
||||
async def upload_header_image(site_id: str, file: UploadFile = File(...), db: Session = Depends(get_db), _=Depends(get_current_admin)):
|
||||
site = db.query(Site).filter(Site.site_id == site_id).first()
|
||||
if not site:
|
||||
raise HTTPException(status_code=404, detail="Site not found")
|
||||
|
||||
if not file.content_type or not file.content_type.startswith("image/"):
|
||||
raise HTTPException(status_code=400, detail="File must be an image")
|
||||
|
||||
os.makedirs(HEADER_IMAGE_DIR, exist_ok=True)
|
||||
|
||||
if site.menu_header_image_url:
|
||||
old_path = os.path.join(HEADER_IMAGE_DIR, os.path.basename(site.menu_header_image_url))
|
||||
if os.path.exists(old_path):
|
||||
os.remove(old_path)
|
||||
|
||||
filename = f"{site.site_id}_{uuid.uuid4().hex[:8]}.png"
|
||||
filepath = os.path.join(HEADER_IMAGE_DIR, filename)
|
||||
|
||||
contents = await file.read()
|
||||
with open(filepath, "wb") as f:
|
||||
f.write(contents)
|
||||
|
||||
site.menu_header_image_url = f"/static/site_headers/{filename}"
|
||||
db.commit()
|
||||
db.refresh(site)
|
||||
return site
|
||||
|
||||
|
||||
@router.delete("/{site_id}/header-image", response_model=SiteOut)
|
||||
def delete_header_image(site_id: str, db: Session = Depends(get_db), _=Depends(get_current_admin)):
|
||||
site = db.query(Site).filter(Site.site_id == site_id).first()
|
||||
if not site:
|
||||
raise HTTPException(status_code=404, detail="Site not found")
|
||||
|
||||
if site.menu_header_image_url:
|
||||
old_path = os.path.join(HEADER_IMAGE_DIR, os.path.basename(site.menu_header_image_url))
|
||||
if os.path.exists(old_path):
|
||||
os.remove(old_path)
|
||||
site.menu_header_image_url = None
|
||||
db.commit()
|
||||
db.refresh(site)
|
||||
return site
|
||||
|
||||
|
||||
@router.post("/{site_id}/lock", response_model=SiteOut)
|
||||
def lock_site(site_id: str, body: LockRequest, db: Session = Depends(get_db), _=Depends(get_current_admin)):
|
||||
site = db.query(Site).filter(Site.site_id == site_id).first()
|
||||
|
||||
@@ -15,6 +15,11 @@ class SiteUpdate(BaseModel):
|
||||
contact_email: str | None = None
|
||||
license_expires_at: datetime | None = None
|
||||
waiter_domain: str | None = None
|
||||
menu_mode: str | None = None
|
||||
menu_tagline_en: str | None = None
|
||||
menu_tagline_gr: str | None = None
|
||||
menu_hours_en: str | None = None
|
||||
menu_hours_gr: str | None = None
|
||||
|
||||
|
||||
class SiteOut(BaseModel):
|
||||
@@ -32,6 +37,12 @@ class SiteOut(BaseModel):
|
||||
last_seen_ip: str | None
|
||||
last_seen_local_ip: str | None
|
||||
waiter_domain: str | None
|
||||
menu_mode: str
|
||||
menu_tagline_en: str | None
|
||||
menu_tagline_gr: str | None
|
||||
menu_hours_en: str | None
|
||||
menu_hours_gr: str | None
|
||||
menu_header_image_url: str | None
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user