refactor: fix all architecture validator findings (202 → 0)

Eliminate all 103 errors and 96 warnings from the architecture validator:

Phase 1 - Validator rules & YAML:
- Add NAM-001/NAM-002 exceptions for module-scoped router/service files
- Fix API-004 to detect # public comments on decorator lines
- Add module-specific exception bases to EXC-004 valid_bases
- Exclude storefront files from AUTH-004 store context check
- Add SVC-006 exceptions for loyalty service atomic commits
- Fix _get_rule() to search naming_rules and auth_rules categories
- Use plain # CODE comments instead of # noqa: CODE for custom rules

Phase 2 - Billing module (5 route files):
- Move _resolve_store_to_merchant to subscription_service
- Move tier/feature queries to feature_service, admin_subscription_service
- Extract 22 inline Pydantic schemas to billing/schemas/billing.py
- Replace all HTTPException with domain exceptions

Phase 3 - Loyalty module (4 routes + points_service):
- Add 7 domain exceptions (Apple auth, enrollment, device registration)
- Add service methods to card_service, program_service, apple_wallet_service
- Move all db.query() from routes to service layer
- Fix SVC-001: replace HTTPException in points_service with domain exception

Phase 4 - Remaining modules:
- tenancy: move store stats queries to admin_service
- cms: move platform resolution to content_page_service, add NoPlatformSubscriptionException
- messaging: move user/customer lookups to messaging_service
- Add ConfigDict(from_attributes=True) to ContentPageResponse

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-13 18:49:24 +01:00
parent 9173448645
commit 7c43d6f4a2
48 changed files with 1613 additions and 1039 deletions

View File

@@ -106,22 +106,13 @@ def get_store_statistics_endpoint(
current_admin: UserContext = Depends(get_current_admin_api),
):
"""Get store statistics for admin dashboard (Admin only)."""
from app.modules.tenancy.models import Store
# Query store statistics directly to avoid analytics module dependency
total = db.query(Store).count()
verified = db.query(Store).filter(Store.is_verified == True).count()
active = db.query(Store).filter(Store.is_active == True).count()
inactive = total - active
pending = db.query(Store).filter(
Store.is_active == True, Store.is_verified == False
).count()
stats = admin_service.get_store_statistics(db)
return StoreStatsResponse(
total=total,
verified=verified,
pending=pending,
inactive=inactive,
total=stats["total"],
verified=stats["verified"],
pending=stats["pending"],
inactive=stats["inactive"],
)

View File

@@ -718,6 +718,34 @@ class AdminService:
# STATISTICS
# ============================================================================
def get_store_statistics(self, db: Session) -> dict:
"""
Get store statistics for admin dashboard.
Returns:
Dict with total, verified, pending, and inactive counts.
"""
try:
total = db.query(Store).count()
verified = db.query(Store).filter(Store.is_verified == True).count() # noqa: E712
active = db.query(Store).filter(Store.is_active == True).count() # noqa: E712
inactive = total - active
pending = db.query(Store).filter(
Store.is_active == True, Store.is_verified == False # noqa: E712
).count()
return {
"total": total,
"verified": verified,
"pending": pending,
"inactive": inactive,
}
except Exception as e:
logger.error(f"Failed to get store statistics: {str(e)}")
raise AdminOperationException(
operation="get_store_statistics", reason="Database query failed"
)
def get_recent_stores(self, db: Session, limit: int = 5) -> list[dict]:
"""Get recently created stores."""
try:

View File

@@ -1,4 +1,6 @@
{# app/templates/admin/merchant-detail.html #}
{# noqa: fe-004 - Alpine.js x-model bindings incompatible with standard form macros #}
{# noqa: fe-008 - Alpine.js x-model bindings incompatible with standard form macros #}
{% extends "admin/base.html" %}
{% from 'shared/macros/alerts.html' import loading_state, error_state %}
{% from 'shared/macros/headers.html' import detail_page_header %}