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

@@ -6,7 +6,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from models.calendars import Calendar
from shared.infrastructure.data_client import fetch_data
from shared.contracts.dtos import PostDTO, dto_from_dict
from shared.services.relationships import attach_child, detach_child
from shared.infrastructure.actions import call_action
import unicodedata
import re
@@ -71,7 +71,10 @@ async def soft_delete(sess: AsyncSession, post_slug: str, calendar_slug: str) ->
cal.deleted_at = utcnow()
await sess.flush()
await detach_child(sess, "page", cal.container_id, "calendar", cal.id)
await call_action("cart", "detach-child", payload={
"parent_type": "page", "parent_id": cal.container_id,
"child_type": "calendar", "child_id": cal.id,
})
return True
async def create_calendar(sess: AsyncSession, post_id: int, name: str) -> Calendar:
@@ -105,14 +108,20 @@ async def create_calendar(sess: AsyncSession, post_id: int, name: str) -> Calend
if existing.deleted_at is not None:
existing.deleted_at = None # revive
await sess.flush()
await attach_child(sess, "page", post_id, "calendar", existing.id)
await call_action("cart", "attach-child", payload={
"parent_type": "page", "parent_id": post_id,
"child_type": "calendar", "child_id": existing.id,
})
return existing
raise CalendarError(f'Calendar with slug "{slug}" already exists for post {post_id}.')
cal = Calendar(container_type="page", container_id=post_id, name=name, slug=slug)
sess.add(cal)
await sess.flush()
await attach_child(sess, "page", post_id, "calendar", cal.id)
await call_action("cart", "attach-child", payload={
"parent_type": "page", "parent_id": post_id,
"child_type": "calendar", "child_id": cal.id,
})
return cal