Eliminate all 103 errors and 96 warnings from the architecture validator: Phase 1 - Validator rules & YAML: - Add NAM-001/NAM-002 exceptions for module-scoped router/service files - Fix API-004 to detect # public comments on decorator lines - Add module-specific exception bases to EXC-004 valid_bases - Exclude storefront files from AUTH-004 store context check - Add SVC-006 exceptions for loyalty service atomic commits - Fix _get_rule() to search naming_rules and auth_rules categories - Use plain # CODE comments instead of # noqa: CODE for custom rules Phase 2 - Billing module (5 route files): - Move _resolve_store_to_merchant to subscription_service - Move tier/feature queries to feature_service, admin_subscription_service - Extract 22 inline Pydantic schemas to billing/schemas/billing.py - Replace all HTTPException with domain exceptions Phase 3 - Loyalty module (4 routes + points_service): - Add 7 domain exceptions (Apple auth, enrollment, device registration) - Add service methods to card_service, program_service, apple_wallet_service - Move all db.query() from routes to service layer - Fix SVC-001: replace HTTPException in points_service with domain exception Phase 4 - Remaining modules: - tenancy: move store stats queries to admin_service - cms: move platform resolution to content_page_service, add NoPlatformSubscriptionException - messaging: move user/customer lookups to messaging_service - Add ConfigDict(from_attributes=True) to ContentPageResponse Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
203 lines
6.5 KiB
Python
203 lines
6.5 KiB
Python
# app/modules/cms/schemas/content_page.py
|
|
"""
|
|
Content Page Pydantic schemas for API request/response validation.
|
|
|
|
Schemas are organized by context:
|
|
- Admin: Full CRUD with platform-level access
|
|
- Store: Store-scoped CRUD with usage limits
|
|
- Public/Shop: Read-only public access
|
|
"""
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
# ============================================================================
|
|
# ADMIN SCHEMAS
|
|
# ============================================================================
|
|
|
|
|
|
class ContentPageCreate(BaseModel):
|
|
"""Schema for creating a content page (admin)."""
|
|
|
|
slug: str = Field(
|
|
...,
|
|
max_length=100,
|
|
description="URL-safe identifier (about, faq, contact, etc.)",
|
|
)
|
|
title: str = Field(..., max_length=200, description="Page title")
|
|
content: str = Field(..., description="HTML or Markdown content")
|
|
content_format: str = Field(
|
|
default="html", description="Content format: html or markdown"
|
|
)
|
|
template: str = Field(
|
|
default="default",
|
|
max_length=50,
|
|
description="Template name (default, minimal, modern)",
|
|
)
|
|
meta_description: str | None = Field(
|
|
None, max_length=300, description="SEO meta description"
|
|
)
|
|
meta_keywords: str | None = Field(None, max_length=300, description="SEO keywords")
|
|
is_published: bool = Field(default=False, description="Publish immediately")
|
|
show_in_footer: bool = Field(default=True, description="Show in footer navigation")
|
|
show_in_header: bool = Field(default=False, description="Show in header navigation")
|
|
show_in_legal: bool = Field(
|
|
default=False, description="Show in legal/bottom bar (next to copyright)"
|
|
)
|
|
display_order: int = Field(default=0, description="Display order (lower = first)")
|
|
store_id: int | None = Field(
|
|
None, description="Store ID (None for platform default)"
|
|
)
|
|
|
|
|
|
class ContentPageUpdate(BaseModel):
|
|
"""Schema for updating a content page (admin)."""
|
|
|
|
title: str | None = Field(None, max_length=200)
|
|
content: str | None = None
|
|
content_format: str | None = None
|
|
template: str | None = Field(None, max_length=50)
|
|
meta_description: str | None = Field(None, max_length=300)
|
|
meta_keywords: str | None = Field(None, max_length=300)
|
|
is_published: bool | None = None
|
|
show_in_footer: bool | None = None
|
|
show_in_header: bool | None = None
|
|
show_in_legal: bool | None = None
|
|
display_order: int | None = None
|
|
|
|
|
|
class ContentPageResponse(BaseModel):
|
|
"""Schema for content page response (admin/store)."""
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
platform_id: int | None = None
|
|
platform_code: str | None = None
|
|
platform_name: str | None = None
|
|
store_id: int | None
|
|
store_name: str | None
|
|
slug: str
|
|
title: str
|
|
content: str
|
|
content_format: str
|
|
template: str | None = None
|
|
meta_description: str | None
|
|
meta_keywords: str | None
|
|
is_published: bool
|
|
published_at: str | None
|
|
display_order: int
|
|
show_in_footer: bool
|
|
show_in_header: bool
|
|
show_in_legal: bool
|
|
is_platform_page: bool = False
|
|
is_platform_default: bool = False # Deprecated: use is_platform_page
|
|
is_store_default: bool = False
|
|
is_store_override: bool = False
|
|
page_tier: str | None = None
|
|
created_at: str
|
|
updated_at: str
|
|
created_by: int | None
|
|
updated_by: int | None
|
|
|
|
|
|
class HomepageSectionsResponse(BaseModel):
|
|
"""Response containing homepage sections with platform language info."""
|
|
|
|
sections: dict | None = None
|
|
supported_languages: list[str] = Field(default_factory=lambda: ["fr", "de", "en"])
|
|
default_language: str = "fr"
|
|
|
|
|
|
class SectionUpdateResponse(BaseModel):
|
|
"""Response after updating sections."""
|
|
|
|
message: str
|
|
sections: dict | None = None
|
|
|
|
|
|
# ============================================================================
|
|
# STORE SCHEMAS
|
|
# ============================================================================
|
|
|
|
|
|
class StoreContentPageCreate(BaseModel):
|
|
"""Schema for creating a store content page."""
|
|
|
|
slug: str = Field(
|
|
...,
|
|
max_length=100,
|
|
description="URL-safe identifier (about, faq, contact, etc.)",
|
|
)
|
|
title: str = Field(..., max_length=200, description="Page title")
|
|
content: str = Field(..., description="HTML or Markdown content")
|
|
content_format: str = Field(
|
|
default="html", description="Content format: html or markdown"
|
|
)
|
|
meta_description: str | None = Field(
|
|
None, max_length=300, description="SEO meta description"
|
|
)
|
|
meta_keywords: str | None = Field(None, max_length=300, description="SEO keywords")
|
|
is_published: bool = Field(default=False, description="Publish immediately")
|
|
show_in_footer: bool = Field(default=True, description="Show in footer navigation")
|
|
show_in_header: bool = Field(default=False, description="Show in header navigation")
|
|
show_in_legal: bool = Field(
|
|
default=False, description="Show in legal/bottom bar (next to copyright)"
|
|
)
|
|
display_order: int = Field(default=0, description="Display order (lower = first)")
|
|
|
|
|
|
class StoreContentPageUpdate(BaseModel):
|
|
"""Schema for updating a store content page."""
|
|
|
|
title: str | None = Field(None, max_length=200)
|
|
content: str | None = None
|
|
content_format: str | None = None
|
|
meta_description: str | None = Field(None, max_length=300)
|
|
meta_keywords: str | None = Field(None, max_length=300)
|
|
is_published: bool | None = None
|
|
show_in_footer: bool | None = None
|
|
show_in_header: bool | None = None
|
|
show_in_legal: bool | None = None
|
|
display_order: int | None = None
|
|
|
|
|
|
class CMSUsageResponse(BaseModel):
|
|
"""Schema for CMS usage statistics."""
|
|
|
|
total_pages: int
|
|
custom_pages: int
|
|
override_pages: int
|
|
pages_limit: int | None
|
|
custom_pages_limit: int | None
|
|
can_create_page: bool
|
|
can_create_custom: bool
|
|
usage_percent: float
|
|
custom_usage_percent: float
|
|
|
|
|
|
# ============================================================================
|
|
# PUBLIC/SHOP SCHEMAS
|
|
# ============================================================================
|
|
|
|
|
|
class PublicContentPageResponse(BaseModel):
|
|
"""Public content page response (no internal IDs)."""
|
|
|
|
slug: str
|
|
title: str
|
|
content: str
|
|
content_format: str
|
|
meta_description: str | None
|
|
meta_keywords: str | None
|
|
published_at: str | None
|
|
|
|
|
|
class ContentPageListItem(BaseModel):
|
|
"""Content page list item for navigation."""
|
|
|
|
slug: str
|
|
title: str
|
|
show_in_footer: bool
|
|
show_in_header: bool
|
|
display_order: int
|