wrongmove/crawler/services/district_service.py
Viktor Barzin 150342bb9e
Refactor codebase following Clean Code principles and add 229 tests
- Extract helpers to reduce function sizes (listing_tasks, app.py, query.py, listing_fetcher)
  - Replace nonlocal mutations with _PipelineState dataclass in listing_tasks
  - Fix bugs: isinstance→equality check in repository, verify_exp for OIDC tokens
  - Consolidate duplicate filter methods in listing_repository
  - Move hardcoded config to env vars with backward-compatible defaults
  - Simplify CLI decorator to auto-build QueryParameters
  - Add deprecation docstring to data_access.py
  - Test count: 158 → 387 (all passing)
2026-02-07 20:19:57 +00:00

37 lines
971 B
Python

"""Unified district service - shared between CLI and HTTP API."""
from rec.districts import get_districts as _get_districts
def get_all_districts() -> dict[str, str]:
"""Get all available districts with their region IDs.
Used by:
- CLI: --district option choices
- API: GET /api/get_districts
Returns:
Dictionary mapping district names to region IDs
"""
return _get_districts()
def get_district_names() -> list[str]:
"""Get list of all district names.
Returns:
List of district names
"""
return list(_get_districts().keys())
def validate_districts(district_names: list[str]) -> list[str]:
"""Validate that district names exist.
Args:
district_names: List of district names to validate
Returns:
List of invalid district names (empty if all valid)
"""
valid_districts = set(_get_districts().keys())
return [d for d in district_names if d not in valid_districts]