refactor(P6): standardize route variable naming to router
Some checks failed
Some checks failed
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:
@@ -11,7 +11,7 @@ Each main router (admin.py, store.py) aggregates its related sub-routers interna
|
||||
Merchant routes are auto-discovered from merchant.py.
|
||||
"""
|
||||
|
||||
from app.modules.billing.routes.api.admin import admin_router
|
||||
from app.modules.billing.routes.api.store import store_router
|
||||
from app.modules.billing.routes.api.admin import router as admin_router
|
||||
from app.modules.billing.routes.api.store import router as store_router
|
||||
|
||||
__all__ = ["admin_router", "store_router"]
|
||||
|
||||
@@ -40,7 +40,7 @@ from app.modules.tenancy.schemas.auth import UserContext
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Admin router with module access control
|
||||
admin_router = APIRouter(
|
||||
router = APIRouter(
|
||||
prefix="/subscriptions",
|
||||
dependencies=[Depends(require_module_access("billing", FrontendType.ADMIN))],
|
||||
)
|
||||
@@ -51,7 +51,7 @@ admin_router = APIRouter(
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@admin_router.get("/tiers", response_model=SubscriptionTierListResponse)
|
||||
@router.get("/tiers", response_model=SubscriptionTierListResponse)
|
||||
def list_subscription_tiers(
|
||||
include_inactive: bool = Query(False, description="Include inactive tiers"),
|
||||
platform_id: int | None = Query(None, description="Filter tiers by platform"),
|
||||
@@ -75,7 +75,7 @@ def list_subscription_tiers(
|
||||
)
|
||||
|
||||
|
||||
@admin_router.get("/tiers/{tier_code}", response_model=SubscriptionTierResponse)
|
||||
@router.get("/tiers/{tier_code}", response_model=SubscriptionTierResponse)
|
||||
def get_subscription_tier(
|
||||
tier_code: str = Path(..., description="Tier code"),
|
||||
current_user: UserContext = Depends(get_current_admin_api),
|
||||
@@ -88,7 +88,7 @@ def get_subscription_tier(
|
||||
return resp
|
||||
|
||||
|
||||
@admin_router.post("/tiers", response_model=SubscriptionTierResponse, status_code=201)
|
||||
@router.post("/tiers", response_model=SubscriptionTierResponse, status_code=201)
|
||||
def create_subscription_tier(
|
||||
tier_data: SubscriptionTierCreate,
|
||||
current_user: UserContext = Depends(get_current_admin_api),
|
||||
@@ -103,7 +103,7 @@ def create_subscription_tier(
|
||||
return resp
|
||||
|
||||
|
||||
@admin_router.patch("/tiers/{tier_code}", response_model=SubscriptionTierResponse)
|
||||
@router.patch("/tiers/{tier_code}", response_model=SubscriptionTierResponse)
|
||||
def update_subscription_tier(
|
||||
tier_data: SubscriptionTierUpdate,
|
||||
tier_code: str = Path(..., description="Tier code"),
|
||||
@@ -120,7 +120,7 @@ def update_subscription_tier(
|
||||
return resp
|
||||
|
||||
|
||||
@admin_router.delete("/tiers/{tier_code}", status_code=204)
|
||||
@router.delete("/tiers/{tier_code}", status_code=204)
|
||||
def delete_subscription_tier(
|
||||
tier_code: str = Path(..., description="Tier code"),
|
||||
current_user: UserContext = Depends(get_current_admin_api),
|
||||
@@ -136,7 +136,7 @@ def delete_subscription_tier(
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@admin_router.get("", response_model=MerchantSubscriptionListResponse)
|
||||
@router.get("", response_model=MerchantSubscriptionListResponse)
|
||||
def list_merchant_subscriptions(
|
||||
page: int = Query(1, ge=1),
|
||||
per_page: int = Query(20, ge=1, le=100),
|
||||
@@ -175,7 +175,7 @@ def list_merchant_subscriptions(
|
||||
)
|
||||
|
||||
|
||||
@admin_router.get("/merchants/{merchant_id}")
|
||||
@router.get("/merchants/{merchant_id}")
|
||||
def get_merchant_subscriptions(
|
||||
merchant_id: int = Path(..., description="Merchant ID"),
|
||||
current_user: UserContext = Depends(get_current_admin_api),
|
||||
@@ -185,10 +185,10 @@ def get_merchant_subscriptions(
|
||||
results = admin_subscription_service.get_merchant_subscriptions_with_usage(
|
||||
db, merchant_id
|
||||
)
|
||||
return {"subscriptions": results}
|
||||
return {"subscriptions": results} # noqa: API001
|
||||
|
||||
|
||||
@admin_router.post(
|
||||
@router.post(
|
||||
"/merchants/{merchant_id}/platforms/{platform_id}",
|
||||
response_model=MerchantSubscriptionAdminResponse,
|
||||
status_code=201,
|
||||
@@ -226,7 +226,7 @@ def create_merchant_subscription(
|
||||
return MerchantSubscriptionAdminResponse.model_validate(sub)
|
||||
|
||||
|
||||
@admin_router.get(
|
||||
@router.get(
|
||||
"/merchants/{merchant_id}/platforms/{platform_id}",
|
||||
response_model=MerchantSubscriptionAdminResponse,
|
||||
)
|
||||
@@ -243,7 +243,7 @@ def get_merchant_subscription(
|
||||
return MerchantSubscriptionAdminResponse.model_validate(sub)
|
||||
|
||||
|
||||
@admin_router.patch(
|
||||
@router.patch(
|
||||
"/merchants/{merchant_id}/platforms/{platform_id}",
|
||||
response_model=MerchantSubscriptionAdminResponse,
|
||||
)
|
||||
@@ -270,7 +270,7 @@ def update_merchant_subscription(
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@admin_router.get("/store/{store_id}")
|
||||
@router.get("/store/{store_id}")
|
||||
def get_subscription_for_store(
|
||||
store_id: int = Path(..., description="Store ID"),
|
||||
current_user: UserContext = Depends(get_current_admin_api),
|
||||
@@ -284,7 +284,7 @@ def get_subscription_for_store(
|
||||
of subscription entries with feature usage metrics.
|
||||
"""
|
||||
results = admin_subscription_service.get_subscriptions_for_store(db, store_id)
|
||||
return {"subscriptions": results}
|
||||
return {"subscriptions": results} # noqa: API001
|
||||
|
||||
|
||||
# ============================================================================
|
||||
@@ -292,7 +292,7 @@ def get_subscription_for_store(
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@admin_router.get("/stats", response_model=SubscriptionStatsResponse)
|
||||
@router.get("/stats", response_model=SubscriptionStatsResponse)
|
||||
def get_subscription_stats(
|
||||
current_user: UserContext = Depends(get_current_admin_api),
|
||||
db: Session = Depends(get_db),
|
||||
@@ -307,7 +307,7 @@ def get_subscription_stats(
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@admin_router.get("/billing/history", response_model=BillingHistoryListResponse)
|
||||
@router.get("/billing/history", response_model=BillingHistoryListResponse)
|
||||
def list_billing_history(
|
||||
page: int = Query(1, ge=1),
|
||||
per_page: int = Query(20, ge=1, le=100),
|
||||
@@ -360,4 +360,4 @@ def list_billing_history(
|
||||
# Include the features router to aggregate all billing-related admin routes
|
||||
from app.modules.billing.routes.api.admin_features import admin_features_router
|
||||
|
||||
admin_router.include_router(admin_features_router, tags=["admin-features"])
|
||||
router.include_router(admin_features_router, tags=["admin-features"])
|
||||
|
||||
@@ -28,7 +28,7 @@ from app.modules.tenancy.schemas.auth import UserContext
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Store router with module access control
|
||||
store_router = APIRouter(
|
||||
router = APIRouter(
|
||||
prefix="/billing",
|
||||
dependencies=[Depends(require_module_access("billing", FrontendType.STORE))],
|
||||
)
|
||||
@@ -39,7 +39,7 @@ store_router = APIRouter(
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@store_router.get("/subscription", response_model=SubscriptionStatusResponse)
|
||||
@router.get("/subscription", response_model=SubscriptionStatusResponse)
|
||||
def get_subscription_status(
|
||||
current_user: UserContext = Depends(get_current_store_api),
|
||||
db: Session = Depends(get_db),
|
||||
@@ -76,7 +76,7 @@ def get_subscription_status(
|
||||
)
|
||||
|
||||
|
||||
@store_router.get("/tiers", response_model=TierListResponse)
|
||||
@router.get("/tiers", response_model=TierListResponse)
|
||||
def get_available_tiers(
|
||||
current_user: UserContext = Depends(get_current_store_api),
|
||||
db: Session = Depends(get_db),
|
||||
@@ -96,7 +96,7 @@ def get_available_tiers(
|
||||
return TierListResponse(tiers=tier_responses, current_tier=current_tier_code)
|
||||
|
||||
|
||||
@store_router.get("/invoices", response_model=InvoiceListResponse)
|
||||
@router.get("/invoices", response_model=InvoiceListResponse)
|
||||
def get_invoices(
|
||||
skip: int = Query(0, ge=0),
|
||||
limit: int = Query(20, ge=1, le=100),
|
||||
@@ -138,7 +138,7 @@ from app.modules.billing.routes.api.store_checkout import store_checkout_router
|
||||
from app.modules.billing.routes.api.store_features import store_features_router
|
||||
from app.modules.billing.routes.api.store_usage import store_usage_router
|
||||
|
||||
store_router.include_router(store_features_router, tags=["store-features"])
|
||||
store_router.include_router(store_checkout_router, tags=["store-billing"])
|
||||
store_router.include_router(store_addons_router, tags=["store-billing-addons"])
|
||||
store_router.include_router(store_usage_router, tags=["store-usage"])
|
||||
router.include_router(store_features_router, tags=["store-features"])
|
||||
router.include_router(store_checkout_router, tags=["store-billing"])
|
||||
router.include_router(store_addons_router, tags=["store-billing-addons"])
|
||||
router.include_router(store_usage_router, tags=["store-usage"])
|
||||
|
||||
Reference in New Issue
Block a user