"""Printing problems (plan step 6.10, services/print_problems.py): the tickets that didn't print, for whoever may act on their orders (the managers see all), and the three ways out: print again, send to another printer, mark as handled. Live event: `print.problems`.""" from __future__ import annotations from fastapi import APIRouter, Depends from pydantic import BaseModel from sqlalchemy.orm import Session from core.access.deps import require_any from database import get_db from services import print_problems as svc router = APIRouter() _STAFF = require_any("ordering.orders.open", "core.dashboard.access") @router.get("") def list_problems(db: Session = Depends(get_db), user=Depends(_STAFF)): """{problems: [...oldest first], printers: [{id, name}]} (the printers a ticket can go to).""" return {"problems": svc.problems(db, user), "printers": svc.printers(db)} @router.post("/{job_id}/retry") def retry(job_id: int, db: Session = Depends(get_db), user=Depends(_STAFF)): return svc.retry(db, job_id, user) class RedirectBody(BaseModel): printer_id: int @router.post("/{job_id}/redirect") def redirect(job_id: int, body: RedirectBody, db: Session = Depends(get_db), user=Depends(_STAFF)): return svc.redirect(db, job_id, body.printer_id, user) @router.post("/{job_id}/handled") def handled(job_id: int, db: Session = Depends(get_db), user=Depends(_STAFF)): return svc.handled(db, job_id, user)