feat(route-sections): add dynamic route sections
Replace hardcoded homepage featured route groups with a fully managed dynamic system: - add database models RouteSection and RouteSectionProduct for storing route groups and their associated products - create Alembic migration 0004_route_sections for the new tables - extend SiteConfigPatchIn schema with subtitle and productIds fields - refactor shared site_config utility to load dynamic route sections instead of fixed groups - implement admin CRUD API with validation for duplicate/conflicting product associations - update public and admin API documentation to reflect the new system - add default route section seed data and comprehensive test coverage
This commit is contained in:
@@ -1,16 +1,10 @@
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session, selectinload
|
||||
from ..models import Campaign, CtaBanner, Destination, HeroSlide, MapImage, Product, ThemeCard
|
||||
from ..models import Campaign, CtaBanner, Destination, HeroSlide, MapImage, ThemeCard
|
||||
from ..route_sections import route_section_dict, route_section_query
|
||||
from ..serializers import destination_dict, model_dict
|
||||
|
||||
|
||||
ROUTE_SECTION_LABELS = [
|
||||
("routes", "经典人文打卡线路", 0, 8),
|
||||
("routes-outdoor", "极限山野户外野咖线路", 8, 16),
|
||||
("routes-mix", "人文+户外综合混搭线路", 16, 24),
|
||||
]
|
||||
|
||||
|
||||
def site_config(db: Session, active_only: bool, include_public_extras: bool = True) -> dict:
|
||||
hero_stmt = select(HeroSlide).order_by(HeroSlide.sortOrder.asc())
|
||||
destination_stmt = select(Destination).options(selectinload(Destination.aliases)).order_by(Destination.sortOrder.asc())
|
||||
@@ -38,12 +32,9 @@ def site_config(db: Session, active_only: bool, include_public_extras: bool = Tr
|
||||
}
|
||||
if include_public_extras:
|
||||
campaigns = db.scalars(select(Campaign).where(Campaign.status == "published").order_by(Campaign.updatedAt.desc())).all()
|
||||
products = db.scalars(
|
||||
select(Product).where(Product.status == "published").order_by(Product.sortWeight.asc(), Product.createdAt.asc()).limit(48)
|
||||
).all()
|
||||
route_sections = db.scalars(route_section_query()).all()
|
||||
if active_only:
|
||||
route_sections = [section for section in route_sections if section.isActive]
|
||||
result["campaigns"] = [model_dict(item) for item in campaigns]
|
||||
result["routeSections"] = [
|
||||
{"id": section_id, "title": title, "productIds": [item.id for item in products[start:end]]}
|
||||
for section_id, title, start, end in ROUTE_SECTION_LABELS
|
||||
]
|
||||
result["routeSections"] = [route_section_dict(item, public=True) for item in route_sections]
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user