Move container_relations to cart service for cross-service ownership

container_relations is a generic parent/child graph used by blog
(menu_nodes), market (marketplaces), and events (calendars). Move it
to cart as shared infrastructure. All services now call cart actions
(attach-child/detach-child) instead of querying the table directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 17:49:30 +00:00
parent dd52417241
commit 1f3d98ecc1
7 changed files with 154 additions and 14 deletions

View File

@@ -12,7 +12,7 @@ from shared.models.market import Product
from shared.models.market_place import MarketPlace
from shared.browser.app.utils import utcnow
from shared.contracts.dtos import MarketPlaceDTO, ProductDTO
from shared.services.relationships import attach_child, detach_child
from shared.infrastructure.actions import call_action
def _mp_to_dto(mp: MarketPlace) -> MarketPlaceDTO:
@@ -93,7 +93,10 @@ class SqlMarketService:
existing.deleted_at = None # revive
existing.name = name
await session.flush()
await attach_child(session, container_type, container_id, "market", existing.id)
await call_action("cart", "attach-child", payload={
"parent_type": container_type, "parent_id": container_id,
"child_type": "market", "child_id": existing.id,
})
return _mp_to_dto(existing)
raise ValueError(f'Market with slug "{slug}" already exists for this container.')
@@ -103,7 +106,10 @@ class SqlMarketService:
)
session.add(market)
await session.flush()
await attach_child(session, container_type, container_id, "market", market.id)
await call_action("cart", "attach-child", payload={
"parent_type": container_type, "parent_id": container_id,
"child_type": "market", "child_id": market.id,
})
return _mp_to_dto(market)
async def soft_delete_marketplace(
@@ -124,5 +130,8 @@ class SqlMarketService:
market.deleted_at = utcnow()
await session.flush()
await detach_child(session, container_type, container_id, "market", market.id)
await call_action("cart", "detach-child", payload={
"parent_type": container_type, "parent_id": container_id,
"child_type": "market", "child_id": market.id,
})
return True