demand_belong_category.py 739 B

12345678910111213141516171819202122232425
  1. """Load demand_belong_category associations."""
  2. from __future__ import annotations
  3. from typing import Any
  4. from supply_infra.db.repositories.demand_belong_category_repo import (
  5. DemandBelongCategoryRepository,
  6. )
  7. from supply_infra.db.session import get_session
  8. def list_demand_belong_categories() -> list[dict[str, Any]]:
  9. """Return all active demand ↔ category rows."""
  10. with get_session() as session:
  11. repo = DemandBelongCategoryRepository(session)
  12. rows = repo.list_active()
  13. return [
  14. {
  15. "id": row.id,
  16. "name": row.name,
  17. "category_id": row.category_id,
  18. "reason": row.reason,
  19. }
  20. for row in rows
  21. ]