refactor: standardize modular architecture patterns
- Rename module definition variables to follow naming convention: - catalog/definition.py: module → catalog_module - checkout/definition.py: module → checkout_module - cart/definition.py: module → cart_module - Add router attachment functions for lazy loading: - get_catalog_module_with_routers() - get_checkout_module_with_routers() - get_cart_module_with_routers() - Move billing exceptions to exceptions.py: - Add backwards-compatible aliases (BillingServiceError, etc.) - Update billing_service.py to import from exceptions.py - Standardize VendorEmailSettingsService DI pattern: - Change from db in __init__ to db as method parameter - Create singleton vendor_email_settings_service instance - Update routes and tests to use new pattern Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,28 @@ from app.modules.base import (
|
||||
)
|
||||
from app.modules.enums import FrontendType
|
||||
|
||||
module = ModuleDefinition(
|
||||
|
||||
# =============================================================================
|
||||
# Router Lazy Imports
|
||||
# =============================================================================
|
||||
|
||||
|
||||
def _get_admin_router():
|
||||
"""Lazy import of admin router to avoid circular imports."""
|
||||
from app.modules.catalog.routes.api.admin import admin_router
|
||||
|
||||
return admin_router
|
||||
|
||||
|
||||
def _get_vendor_router():
|
||||
"""Lazy import of vendor router to avoid circular imports."""
|
||||
from app.modules.catalog.routes.api.vendor import vendor_router
|
||||
|
||||
return vendor_router
|
||||
|
||||
|
||||
# Catalog module definition
|
||||
catalog_module = ModuleDefinition(
|
||||
code="catalog",
|
||||
name="Product Catalog",
|
||||
description="Product catalog browsing and search for storefronts",
|
||||
@@ -85,3 +106,18 @@ module = ModuleDefinition(
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def get_catalog_module_with_routers() -> ModuleDefinition:
|
||||
"""
|
||||
Get catalog module with routers attached.
|
||||
|
||||
This function attaches the routers lazily to avoid circular imports
|
||||
during module initialization.
|
||||
"""
|
||||
catalog_module.admin_router = _get_admin_router()
|
||||
catalog_module.vendor_router = _get_vendor_router()
|
||||
return catalog_module
|
||||
|
||||
|
||||
__all__ = ["catalog_module", "get_catalog_module_with_routers"]
|
||||
|
||||
Reference in New Issue
Block a user