feat: add demand page modules and admin endpoints

Add full backend support for a demand request page, including:
- New database models for demand hero, feature cards, form configuration, and product recommendations
- Alembic migration for the new tables
- Default seed data for demand page components
- Public site config endpoint exposing demand data
- Admin CRUD operations and configuration for demand modules
- Extended lead query filters for source page, keyword, and date range
- Updated Pydantic schemas for lead query parameters
- Comprehensive test coverage for all new endpoints
This commit is contained in:
duanshuwen
2026-07-07 22:03:57 +08:00
parent d11c361aa2
commit fe85197e68
9 changed files with 749 additions and 15 deletions

View File

@@ -0,0 +1,106 @@
"""Add demand page configurable modules.
Revision ID: 0008_demand_page_modules
Revises: 0007_destination_page_modules
Create Date: 2026-07-07
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import inspect
from sqlalchemy.dialects import postgresql
revision = "0008_demand_page_modules"
down_revision = "0007_destination_page_modules"
branch_labels = None
depends_on = None
def upgrade() -> None:
bind = op.get_bind()
existing_tables = set(inspect(bind).get_table_names())
if "DemandHero" not in existing_tables:
op.create_table(
"DemandHero",
sa.Column("id", sa.String(), nullable=False),
sa.Column("title", sa.String(), nullable=False),
sa.Column("kicker", sa.String(), nullable=True),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("steps", postgresql.ARRAY(sa.String()), nullable=False, server_default=sa.text("'{}'")),
sa.Column("sortOrder", sa.Integer(), nullable=False, server_default="0"),
sa.Column("isActive", sa.Boolean(), nullable=False, server_default=sa.true()),
sa.Column("createdAt", sa.DateTime(), nullable=False),
sa.Column("updatedAt", sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
if "DemandFeatureCard" not in existing_tables:
op.create_table(
"DemandFeatureCard",
sa.Column("id", sa.String(), nullable=False),
sa.Column("title", sa.String(), nullable=False),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("sortOrder", sa.Integer(), nullable=False, server_default="0"),
sa.Column("isActive", sa.Boolean(), nullable=False, server_default=sa.true()),
sa.Column("createdAt", sa.DateTime(), nullable=False),
sa.Column("updatedAt", sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
if "DemandForm" not in existing_tables:
op.create_table(
"DemandForm",
sa.Column("id", sa.String(), nullable=False),
sa.Column("destinationLabel", sa.String(), nullable=False, server_default="目的地/玩法"),
sa.Column("destinationPlaceholder", sa.String(), nullable=True),
sa.Column("phoneLabel", sa.String(), nullable=False, server_default="联系方式"),
sa.Column("phonePlaceholder", sa.String(), nullable=True),
sa.Column("noteLabel", sa.String(), nullable=False, server_default="补充说明"),
sa.Column("notePlaceholder", sa.String(), nullable=True),
sa.Column("submitLabel", sa.String(), nullable=False, server_default="提交出行需求"),
sa.Column("chips", postgresql.ARRAY(sa.String()), nullable=False, server_default=sa.text("'{}'")),
sa.Column("isActive", sa.Boolean(), nullable=False, server_default=sa.true()),
sa.Column("createdAt", sa.DateTime(), nullable=False),
sa.Column("updatedAt", sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
if "DemandRecommendation" not in existing_tables:
op.create_table(
"DemandRecommendation",
sa.Column("id", sa.String(), nullable=False),
sa.Column("title", sa.String(), nullable=False),
sa.Column("subtitle", sa.Text(), nullable=True),
sa.Column("sortOrder", sa.Integer(), nullable=False, server_default="0"),
sa.Column("isActive", sa.Boolean(), nullable=False, server_default=sa.true()),
sa.Column("createdAt", sa.DateTime(), nullable=False),
sa.Column("updatedAt", sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
if "DemandRecommendationProduct" not in existing_tables:
op.create_table(
"DemandRecommendationProduct",
sa.Column("recommendationId", sa.String(), nullable=False),
sa.Column("productId", sa.String(), nullable=False),
sa.Column("sortOrder", sa.Integer(), nullable=False, server_default="0"),
sa.ForeignKeyConstraint(["productId"], ["Product.id"], ondelete="CASCADE"),
sa.ForeignKeyConstraint(["recommendationId"], ["DemandRecommendation.id"], ondelete="CASCADE"),
sa.PrimaryKeyConstraint("recommendationId", "productId"),
)
def downgrade() -> None:
bind = op.get_bind()
existing_tables = set(inspect(bind).get_table_names())
for table_name in [
"DemandRecommendationProduct",
"DemandRecommendation",
"DemandForm",
"DemandFeatureCard",
"DemandHero",
]:
if table_name in existing_tables:
op.drop_table(table_name)