feat: Add scene filtering to verticals API
Some checks failed
Deploy Fediversion / deploy (push) Failing after 1s

- GET /verticals now supports ?scene= parameter
- Add GET /verticals/scenes endpoint
- Filter verticals by is_active=true
This commit is contained in:
fullsizemalt 2025-12-28 16:07:46 -08:00
parent 704a8d9a0b
commit 19c5e97e7f

View file

@ -47,12 +47,51 @@ class BulkVerticalPreferencesCreate(BaseModel):
# --- Public endpoints --- # --- Public endpoints ---
@router.get("/", response_model=List[VerticalRead]) @router.get("/", response_model=List[VerticalRead])
def list_verticals(session: Session = Depends(get_session)): def list_verticals(
"""List all available verticals (bands)""" scene: str | None = None,
verticals = session.exec(select(Vertical)).all() session: Session = Depends(get_session)
):
"""List all available verticals (bands), optionally filtered by scene"""
from models import Scene, VerticalScene
if scene:
# Filter by scene
scene_obj = session.exec(select(Scene).where(Scene.slug == scene)).first()
if not scene_obj:
raise HTTPException(status_code=404, detail="Scene not found")
vertical_ids = session.exec(
select(VerticalScene.vertical_id).where(VerticalScene.scene_id == scene_obj.id)
).all()
verticals = session.exec(
select(Vertical)
.where(Vertical.id.in_(vertical_ids))
.where(Vertical.is_active == True)
).all()
else:
verticals = session.exec(
select(Vertical).where(Vertical.is_active == True)
).all()
return verticals return verticals
class SceneRead(BaseModel):
id: int
name: str
slug: str
description: str | None = None
@router.get("/scenes", response_model=List[SceneRead])
def list_scenes(session: Session = Depends(get_session)):
"""List all scenes (genres)"""
from models import Scene
scenes = session.exec(select(Scene)).all()
return scenes
@router.get("/{slug}", response_model=VerticalRead) @router.get("/{slug}", response_model=VerticalRead)
def get_vertical(slug: str, session: Session = Depends(get_session)): def get_vertical(slug: str, session: Session = Depends(get_session)):
"""Get a specific vertical by slug""" """Get a specific vertical by slug"""