2026-09-04 17:34:03 -05:00
|
|
|
"""Collection/franchise endpoints (section 17)."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-09-05 20:08:26 -05:00
|
|
|
from fastapi import APIRouter, Depends, Query
|
2026-09-04 17:34:03 -05:00
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
|
|
|
|
|
|
from app.api.deps import not_found
|
|
|
|
|
from app.core.database import get_db
|
|
|
|
|
from app.core.security import enforce_rate_limit
|
2026-09-05 20:08:26 -05:00
|
|
|
from app.schemas.collection import CollectionDetailOut, CollectionListOut
|
2026-09-04 17:34:03 -05:00
|
|
|
from app.services import collection_service
|
|
|
|
|
|
|
|
|
|
router = APIRouter(
|
|
|
|
|
prefix="/collections", tags=["collections"], dependencies=[Depends(enforce_rate_limit)]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2026-09-05 20:08:26 -05:00
|
|
|
@router.get("", response_model=CollectionListOut)
|
|
|
|
|
async def list_collections(
|
|
|
|
|
page: int = Query(1, ge=1),
|
|
|
|
|
page_size: int = Query(20, ge=1, le=50),
|
|
|
|
|
session: AsyncSession = Depends(get_db),
|
|
|
|
|
) -> CollectionListOut:
|
|
|
|
|
return await collection_service.list_collections(session, page=page, page_size=page_size)
|
|
|
|
|
|
|
|
|
|
|
2026-09-04 17:34:03 -05:00
|
|
|
@router.get("/{aurora_id}", response_model=CollectionDetailOut)
|
|
|
|
|
async def get_collection(
|
|
|
|
|
aurora_id: str, session: AsyncSession = Depends(get_db)
|
|
|
|
|
) -> CollectionDetailOut:
|
|
|
|
|
try:
|
|
|
|
|
return await collection_service.get_collection_detail(session, aurora_id)
|
|
|
|
|
except collection_service.CollectionNotFoundError as exc:
|
|
|
|
|
raise not_found("collection", aurora_id) from exc
|