refactor(arch): use CustomerContext schema for dependency injection
Phase 5 of storefront restructure plan - fix direct model imports in API routes by using schemas for dependency injection. Created CustomerContext schema: - Lightweight Pydantic model for customer data in API routes - Populated from Customer DB model in auth dependency - Contains all fields needed by storefront routes - Includes from_db_model() factory method Updated app/api/deps.py: - _validate_customer_token now returns CustomerContext instead of Customer - Updated docstrings for all customer auth functions Updated module storefront routes: - customers: Uses CustomerContext for profile/address endpoints - orders: Uses CustomerContext for order history endpoints - checkout: Uses CustomerContext for order placement - messaging: Uses CustomerContext for messaging endpoints This enforces the layered architecture (Routes → Services → Models) by ensuring API routes never import database models directly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,9 +9,11 @@ Usage:
|
||||
CustomerRegister,
|
||||
CustomerUpdate,
|
||||
CustomerResponse,
|
||||
CustomerContext,
|
||||
)
|
||||
"""
|
||||
|
||||
from app.modules.customers.schemas.context import CustomerContext
|
||||
from app.modules.customers.schemas.customer import (
|
||||
# Registration & Authentication
|
||||
CustomerRegister,
|
||||
@@ -41,6 +43,8 @@ from app.modules.customers.schemas.customer import (
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
# Context (for dependency injection)
|
||||
"CustomerContext",
|
||||
# Registration & Authentication
|
||||
"CustomerRegister",
|
||||
"CustomerUpdate",
|
||||
|
||||
Reference in New Issue
Block a user