refactor(P6): standardize route variable naming to router
Some checks failed
CI / ruff (push) Successful in 9s
CI / pytest (push) Has been cancelled
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled

All route files (admin.py, store.py) now export `router` instead of
`admin_router`/`store_router`. Consumer code (definition.py, __init__.py)
imports as `router as admin_router` where distinction is needed.
ModuleDefinition fields remain admin_router/store_router.

64 files changed across all modules. Architecture rules, docs, and
migration plan updated. Added noqa:API001 support to validator for
pre-existing raw dict endpoints now visible with standardized router name.
All 1114 tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 11:05:34 +01:00
parent 8c0967e215
commit 30c4593e0f
65 changed files with 376 additions and 355 deletions

View File

@@ -16,10 +16,10 @@ __all__ = [
def __getattr__(name: str):
"""Lazy import routers to avoid circular dependencies."""
if name == "admin_router":
from app.modules.customers.routes.api.admin import admin_router
return admin_router
if name == "store_router":
from app.modules.customers.routes.api.store import store_router
return store_router
if name == "router":
from app.modules.customers.routes.api.admin import router as admin_router
return router
if name == "router":
from app.modules.customers.routes.api.store import router as store_router
return router
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

View File

@@ -21,7 +21,7 @@ from app.modules.enums import FrontendType
from app.modules.tenancy.schemas.auth import UserContext
# Create module-aware router
admin_router = APIRouter(
router = APIRouter(
prefix="/customers",
dependencies=[Depends(require_module_access("customers", FrontendType.ADMIN))],
)
@@ -32,7 +32,7 @@ admin_router = APIRouter(
# ============================================================================
@admin_router.get("", response_model=CustomerListResponse)
@router.get("", response_model=CustomerListResponse)
def list_customers(
store_id: int | None = Query(None, description="Filter by store ID"),
search: str = Query("", description="Search by email, name, or customer number"),
@@ -75,7 +75,7 @@ def list_customers(
# ============================================================================
@admin_router.get("/stats", response_model=CustomerStatisticsResponse)
@router.get("/stats", response_model=CustomerStatisticsResponse)
def get_customer_stats(
store_id: int | None = Query(None, description="Filter by store ID"),
db: Session = Depends(get_db),
@@ -91,7 +91,7 @@ def get_customer_stats(
# ============================================================================
@admin_router.get("/{customer_id}", response_model=CustomerDetailResponse)
@router.get("/{customer_id}", response_model=CustomerDetailResponse)
def get_customer(
customer_id: int,
db: Session = Depends(get_db),
@@ -107,7 +107,7 @@ def get_customer(
# ============================================================================
@admin_router.patch("/{customer_id}/toggle-status", response_model=CustomerMessageResponse)
@router.patch("/{customer_id}/toggle-status", response_model=CustomerMessageResponse)
def toggle_customer_status(
customer_id: int,
db: Session = Depends(get_db),

View File

@@ -25,14 +25,14 @@ from app.modules.enums import FrontendType
from app.modules.tenancy.schemas.auth import UserContext
# Create module-aware router
store_router = APIRouter(
router = APIRouter(
prefix="/customers",
dependencies=[Depends(require_module_access("customers", FrontendType.STORE))],
)
logger = logging.getLogger(__name__)
@store_router.get("", response_model=StoreCustomerListResponse)
@router.get("", response_model=StoreCustomerListResponse)
def get_store_customers(
skip: int = Query(0, ge=0),
limit: int = Query(100, ge=1, le=1000),
@@ -66,7 +66,7 @@ def get_store_customers(
)
@store_router.get("/{customer_id}", response_model=CustomerDetailResponse)
@router.get("/{customer_id}", response_model=CustomerDetailResponse)
def get_customer_details(
customer_id: int,
current_user: UserContext = Depends(get_current_store_api),
@@ -101,7 +101,7 @@ def get_customer_details(
)
@store_router.put("/{customer_id}", response_model=CustomerMessageResponse)
@router.put("/{customer_id}", response_model=CustomerMessageResponse)
def update_customer(
customer_id: int,
customer_data: CustomerUpdate,
@@ -127,7 +127,7 @@ def update_customer(
return CustomerMessageResponse(message="Customer updated successfully")
@store_router.put("/{customer_id}/status", response_model=CustomerMessageResponse)
@router.put("/{customer_id}/status", response_model=CustomerMessageResponse)
def toggle_customer_status(
customer_id: int,
current_user: UserContext = Depends(get_current_store_api),