Implement display artifacts, pricing integrity, draft base and publish preview bundle

This commit is contained in:
greebo
2026-03-19 17:58:17 +03:00
parent 85fb2f4bb9
commit c91c5abf15
35 changed files with 3283 additions and 302 deletions

View File

@@ -9,6 +9,34 @@ from app.models.price_rule import PriceRuleRecord
from app.models.pricing_category import PricingCategoryRecord
async def _ensure_unique_price_rule_target(
*,
session,
scheme_id: str,
target_type: str,
target_ref: str,
exclude_price_rule_id: str | None = None,
) -> None:
stmt = select(PriceRuleRecord).where(
PriceRuleRecord.scheme_id == scheme_id,
PriceRuleRecord.target_type == target_type,
PriceRuleRecord.target_ref == target_ref,
)
result = await session.execute(stmt)
row = result.scalar_one_or_none()
if row is None:
return
if exclude_price_rule_id and row.price_rule_id == exclude_price_rule_id:
return
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail="Pricing rule already exists for this target",
)
async def create_pricing_category(
*,
scheme_id: str,
@@ -96,6 +124,13 @@ async def create_price_rule(
price_rule_id = uuid4().hex
async with AsyncSessionLocal() as session:
await _ensure_unique_price_rule_target(
session=session,
scheme_id=scheme_id,
target_type=target_type,
target_ref=target_ref,
)
row = PriceRuleRecord(
price_rule_id=price_rule_id,
scheme_id=scheme_id,
@@ -136,6 +171,14 @@ async def update_price_rule(
detail="Price rule not found",
)
await _ensure_unique_price_rule_target(
session=session,
scheme_id=scheme_id,
target_type=target_type,
target_ref=target_ref,
exclude_price_rule_id=price_rule_id,
)
row.pricing_category_id = pricing_category_id
row.target_type = target_type
row.target_ref = target_ref