refactor: fix architecture violations with provider patterns and dependency inversion
Major changes: - Add AuditProvider protocol for cross-module audit logging - Move customer order operations to orders module (dependency inversion) - Add customer order metrics via MetricsProvider pattern - Fix missing db parameter in get_admin_context() calls - Move ProductMedia relationship to catalog module (proper ownership) - Add marketplace breakdown stats to marketplace_widgets New files: - contracts/audit.py - AuditProviderProtocol - core/services/audit_aggregator.py - Aggregates audit providers - monitoring/services/audit_provider.py - Monitoring audit implementation - orders/services/customer_order_service.py - Customer order operations - orders/routes/api/vendor_customer_orders.py - Customer order endpoints - catalog/services/product_media_service.py - Product media service - Architecture documentation for patterns Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,14 +4,15 @@ CMS module database models.
|
||||
|
||||
This is the canonical location for CMS models including:
|
||||
- ContentPage: CMS pages (marketing, vendor default pages)
|
||||
- MediaFile: Vendor media library
|
||||
- MediaFile: Vendor media library (generic, consumer-agnostic)
|
||||
- VendorTheme: Vendor storefront theme configuration
|
||||
|
||||
Usage:
|
||||
from app.modules.cms.models import ContentPage, MediaFile, VendorTheme
|
||||
|
||||
For product-media associations:
|
||||
from app.modules.catalog.models import ProductMedia
|
||||
Note: ProductMedia is in the catalog module since it's catalog's association
|
||||
to media files. CMS provides generic media storage, consumers define their
|
||||
own associations.
|
||||
"""
|
||||
|
||||
from app.modules.cms.models.content_page import ContentPage
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
# app/modules/cms/models/media.py
|
||||
"""
|
||||
CORE media file model for vendor media library.
|
||||
Generic media file model for vendor media library.
|
||||
|
||||
This is a CORE framework model used across multiple modules.
|
||||
MediaFile provides vendor-uploaded media files (images, documents, videos).
|
||||
This is a consumer-agnostic media storage model. MediaFile provides
|
||||
vendor-uploaded media files (images, documents, videos) without knowing
|
||||
what entities will use them.
|
||||
|
||||
For product-media associations, use:
|
||||
Modules that need media (catalog, art-gallery, etc.) define their own
|
||||
association tables that reference MediaFile.
|
||||
|
||||
For product-media associations:
|
||||
from app.modules.catalog.models import ProductMedia
|
||||
|
||||
Files are stored in vendor-specific directories:
|
||||
@@ -73,12 +77,8 @@ class MediaFile(Base, TimestampMixin):
|
||||
|
||||
# Relationships
|
||||
vendor = relationship("Vendor", back_populates="media_files")
|
||||
# ProductMedia relationship uses string reference to avoid circular import
|
||||
product_associations = relationship(
|
||||
"ProductMedia",
|
||||
back_populates="media",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
# Note: Consumer-specific associations (ProductMedia, etc.) are defined
|
||||
# in their respective modules. CMS doesn't know about specific consumers.
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_media_vendor_id", "vendor_id"),
|
||||
|
||||
Reference in New Issue
Block a user