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

@@ -25,7 +25,7 @@ from app.modules.cms.schemas import (
StoreContentPageUpdate,
)
from app.modules.cms.services import content_page_service
from app.modules.tenancy.models import User
from app.modules.tenancy.models import User # API-007
from app.modules.tenancy.services.store_service import (
StoreService, # MOD-004 - shared platform service
)
@@ -36,25 +36,6 @@ store_content_pages_router = APIRouter(prefix="/content-pages")
logger = logging.getLogger(__name__)
def _resolve_platform_id(db: Session, store_id: int) -> int | None:
"""Resolve platform_id from store's primary StorePlatform. Returns None if not found."""
from app.modules.tenancy.models import StorePlatform
primary_sp = (
db.query(StorePlatform)
.filter(StorePlatform.store_id == store_id, StorePlatform.is_primary.is_(True))
.first()
)
if primary_sp:
return primary_sp.platform_id
# Fallback: any active store_platform
any_sp = (
db.query(StorePlatform)
.filter(StorePlatform.store_id == store_id, StorePlatform.is_active.is_(True))
.first()
)
return any_sp.platform_id if any_sp else None
# ============================================================================
# STORE CONTENT PAGES
# ============================================================================
@@ -71,7 +52,7 @@ def list_store_pages(
Returns store-specific overrides + platform defaults (store overrides take precedence).
"""
platform_id = _resolve_platform_id(db, current_user.token_store_id)
platform_id = content_page_service.resolve_platform_id(db, current_user.token_store_id)
pages = content_page_service.list_pages_for_store(
db, platform_id=platform_id, store_id=current_user.token_store_id, include_unpublished=include_unpublished
)
@@ -169,11 +150,8 @@ def get_platform_default(
Useful for stores to view the original before/after overriding.
"""
# Get store's platform
platform_id = _resolve_platform_id(db, current_user.token_store_id)
if platform_id is None:
from fastapi import HTTPException
raise HTTPException(status_code=400, detail="Store is not subscribed to any platform")
# Get store's platform (raises NoPlatformSubscriptionException if none)
platform_id = content_page_service.resolve_platform_id_or_raise(db, current_user.token_store_id)
# Get platform default (store_id=None)
page = content_page_service.get_store_default_page(
@@ -198,7 +176,7 @@ def get_page(
Returns store override if exists, otherwise platform default.
"""
platform_id = _resolve_platform_id(db, current_user.token_store_id)
platform_id = content_page_service.resolve_platform_id(db, current_user.token_store_id)
page = content_page_service.get_page_for_store_or_raise(
db,
platform_id=platform_id,

View File

@@ -27,6 +27,7 @@ logger = logging.getLogger(__name__)
# ============================================================================
# public - storefront content pages are publicly accessible
@router.get("/navigation", response_model=list[ContentPageListItem])
def get_navigation_pages(request: Request, db: Session = Depends(get_db)):
"""