Files
photoanalyzer/photo_pipeline/api/routes/inventory.py

37 lines
1.2 KiB
Python

"""Inventory listing and scan API for the review UI."""
from __future__ import annotations
from fastapi import APIRouter, Query, Request
from fastapi.responses import JSONResponse
from photo_pipeline.services.inventory import InventoryService
router = APIRouter(tags=["inventory"])
@router.post("/inventory/scan")
def scan(request: Request):
"""Discover and reconcile the configured library roots (synchronous in Phase A;
a durable job in Phase B)."""
config = request.app.state.config
if not config.library_roots:
return JSONResponse(
status_code=409,
content={"error": {"code": "no_roots", "message": "no library_roots configured"}},
)
result = InventoryService(request.app.state.session_factory).scan(config.library_roots)
return {"counts": result.counts, "total": len(result.asset_ids)}
@router.get("/inventory/assets")
def list_assets(
request: Request,
limit: int = Query(50, ge=1, le=200),
offset: int = Query(0, ge=0),
availability: str | None = None,
q: str | None = None,
) -> dict:
service = InventoryService(request.app.state.session_factory)
return service.list_assets(limit=limit, offset=offset, availability=availability, query=q)