refactor(arch): eliminate all cross-module model imports in service layer
Some checks failed
Some checks failed
Enforce MOD-025/MOD-026 rules: zero top-level cross-module model imports remain in any service file. All 66 files migrated using deferred import patterns (method-body, _get_model() helpers, instance-cached self._Model) and new cross-module service methods in tenancy. Documentation updated with Pattern 6 (deferred imports), migration plan marked complete, and violations status reflects 84→0 service-layer violations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,6 @@ from app.modules.cart.exceptions import (
|
||||
)
|
||||
from app.modules.cart.models.cart import CartItem
|
||||
from app.modules.catalog.exceptions import ProductNotFoundException
|
||||
from app.modules.catalog.models import Product
|
||||
from app.utils.money import cents_to_euros
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -146,19 +145,18 @@ class CartService:
|
||||
)
|
||||
|
||||
# Verify product exists and belongs to store
|
||||
product = (
|
||||
db.query(Product)
|
||||
.filter(
|
||||
and_(
|
||||
Product.id == product_id,
|
||||
Product.store_id == store_id,
|
||||
Product.is_active == True,
|
||||
)
|
||||
)
|
||||
.first()
|
||||
)
|
||||
from app.modules.catalog.services.product_service import product_service
|
||||
|
||||
if not product:
|
||||
try:
|
||||
product = product_service.get_product(db, store_id, product_id)
|
||||
except ProductNotFoundException:
|
||||
logger.error(
|
||||
"[CART_SERVICE] Product not found",
|
||||
extra={"product_id": product_id, "store_id": store_id},
|
||||
)
|
||||
raise ProductNotFoundException(product_id=product_id, store_id=store_id)
|
||||
|
||||
if not product.is_active:
|
||||
logger.error(
|
||||
"[CART_SERVICE] Product not found",
|
||||
extra={"product_id": product_id, "store_id": store_id},
|
||||
@@ -323,19 +321,14 @@ class CartService:
|
||||
)
|
||||
|
||||
# Verify product still exists and is active
|
||||
product = (
|
||||
db.query(Product)
|
||||
.filter(
|
||||
and_(
|
||||
Product.id == product_id,
|
||||
Product.store_id == store_id,
|
||||
Product.is_active == True,
|
||||
)
|
||||
)
|
||||
.first()
|
||||
)
|
||||
from app.modules.catalog.services.product_service import product_service
|
||||
|
||||
if not product:
|
||||
try:
|
||||
product = product_service.get_product(db, store_id, product_id)
|
||||
except ProductNotFoundException:
|
||||
raise ProductNotFoundException(str(product_id))
|
||||
|
||||
if not product.is_active:
|
||||
raise ProductNotFoundException(str(product_id))
|
||||
|
||||
# Check inventory
|
||||
|
||||
Reference in New Issue
Block a user