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>
74 lines
1.8 KiB
Python
74 lines
1.8 KiB
Python
# app/modules/customers/schemas/__init__.py
|
|
"""
|
|
Customers module Pydantic schemas.
|
|
|
|
This is the canonical location for customer schemas.
|
|
|
|
Usage:
|
|
from app.modules.customers.schemas import (
|
|
CustomerRegister,
|
|
CustomerUpdate,
|
|
CustomerResponse,
|
|
CustomerContext,
|
|
)
|
|
"""
|
|
|
|
from app.modules.customers.schemas.context import CustomerContext
|
|
from app.modules.customers.schemas.customer import (
|
|
# Registration & Authentication
|
|
CustomerRegister,
|
|
CustomerUpdate,
|
|
CustomerPasswordChange,
|
|
# Customer Response
|
|
CustomerResponse,
|
|
CustomerListResponse,
|
|
# Address
|
|
CustomerAddressCreate,
|
|
CustomerAddressUpdate,
|
|
CustomerAddressResponse,
|
|
CustomerAddressListResponse,
|
|
# Preferences
|
|
CustomerPreferencesUpdate,
|
|
# Vendor Management
|
|
CustomerMessageResponse,
|
|
VendorCustomerListResponse,
|
|
CustomerDetailResponse,
|
|
CustomerOrderInfo,
|
|
CustomerOrdersResponse,
|
|
CustomerStatisticsResponse,
|
|
# Admin Management
|
|
AdminCustomerItem,
|
|
AdminCustomerListResponse,
|
|
AdminCustomerDetailResponse,
|
|
)
|
|
|
|
__all__ = [
|
|
# Context (for dependency injection)
|
|
"CustomerContext",
|
|
# Registration & Authentication
|
|
"CustomerRegister",
|
|
"CustomerUpdate",
|
|
"CustomerPasswordChange",
|
|
# Customer Response
|
|
"CustomerResponse",
|
|
"CustomerListResponse",
|
|
# Address
|
|
"CustomerAddressCreate",
|
|
"CustomerAddressUpdate",
|
|
"CustomerAddressResponse",
|
|
"CustomerAddressListResponse",
|
|
# Preferences
|
|
"CustomerPreferencesUpdate",
|
|
# Vendor Management
|
|
"CustomerMessageResponse",
|
|
"VendorCustomerListResponse",
|
|
"CustomerDetailResponse",
|
|
"CustomerOrderInfo",
|
|
"CustomerOrdersResponse",
|
|
"CustomerStatisticsResponse",
|
|
# Admin Management
|
|
"AdminCustomerItem",
|
|
"AdminCustomerListResponse",
|
|
"AdminCustomerDetailResponse",
|
|
]
|