Adds the new shows admin screen and drives schedule from it

This commit is contained in:
2026-06-22 04:19:51 +00:00
parent e627fe3637
commit eb9a00f21a
28 changed files with 546 additions and 54 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
View File
@@ -89,6 +89,7 @@ async def update_show(
# Replace all schedule slots
for sched in show.schedules:
await session.delete(sched)
await session.flush() # execute deletes before inserts to avoid UNIQUE conflict
for slot in payload.schedules:
session.add(ShowSchedule(show_id=show.id, **slot.model_dump()))
+59
View File
@@ -0,0 +1,59 @@
"""Shared image upload router — admin-only, reused across all forms."""
import os
import uuid
from fastapi import APIRouter, Depends, HTTPException, UploadFile, status
from app.auth import get_current_admin_user
from app.user_models import User
router = APIRouter()
UPLOAD_DIR = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "uploads",
)
MAX_FILE_SIZE = 5 * 1024 * 1024 # 5 MB
@router.post("/image")
async def upload_image(
file: UploadFile,
current_user: User = Depends(get_current_admin_user),
):
"""Upload an image file. Admin only.
Saves the file to the uploads/ directory with a UUID filename.
Returns the relative URL path.
"""
# Validate MIME type
if not file.content_type or not file.content_type.startswith("image/"):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Only image files are allowed",
)
# Read and validate size
content = await file.read()
if len(content) > MAX_FILE_SIZE:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="File size exceeds 5 MB limit",
)
# Ensure upload directory exists
os.makedirs(UPLOAD_DIR, exist_ok=True)
# Generate unique filename preserving extension
ext = (
os.path.splitext(file.filename or "upload")[1]
if file.filename
else ".bin"
)
filename = f"{uuid.uuid4().hex}{ext}"
filepath = os.path.join(UPLOAD_DIR, filename)
with open(filepath, "wb") as f:
f.write(content)
return {"url": f"uploads/{filename}"}
+2 -1
View File
@@ -10,7 +10,7 @@ from app.config import settings
from app.database import async_session, engine
from app.models import Base, Program, Show, StationConfig, HistoryEntry, TeamMember, CommunityHighlight
from app.user_models import User
from app.api import programs, events, tiers, auth, station_config, history, team, community, shows
from app.api import programs, events, tiers, auth, station_config, history, team, community, shows, upload
async def _ensure_station_config(session):
@@ -100,6 +100,7 @@ app.include_router(history.router, prefix="/api/history", tags=["history"])
app.include_router(team.router, prefix="/api/team", tags=["team"])
app.include_router(community.router, prefix="/api/community", tags=["community"])
app.include_router(shows.router, prefix="/api/shows", tags=["shows"])
app.include_router(upload.router, prefix="/api/upload", tags=["upload"])
# Serve uploaded files (dev only — Nginx handles this in production)
if settings.ENV != "production":