Migrate callers from attach-child/detach-child to relate/unrelate API
Switch all cross-service relation calls to the new registry-aware relate/unrelate/can-relate actions, and consolidate per-service container-nav fragment fetches into the generic relations handler. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -215,16 +215,17 @@ def register():
|
||||
ticket_type_id=tt.id,
|
||||
)
|
||||
|
||||
# Fetch container nav from market (skip calendar — we're on a calendar page)
|
||||
# Fetch container nav from relations (exclude calendar — we're on a calendar page)
|
||||
container_nav_html = ""
|
||||
post_data = getattr(g, "post_data", None)
|
||||
if post_data:
|
||||
post_id = post_data["post"]["id"]
|
||||
post_slug = post_data["post"]["slug"]
|
||||
container_nav_html = await fetch_fragment("market", "container-nav", params={
|
||||
container_nav_html = await fetch_fragment("relations", "container-nav", params={
|
||||
"container_type": "page",
|
||||
"container_id": str(post_id),
|
||||
"post_slug": post_slug,
|
||||
"exclude": "page->calendar",
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
@@ -71,9 +71,9 @@ async def soft_delete(sess: AsyncSession, post_slug: str, calendar_slug: str) ->
|
||||
|
||||
cal.deleted_at = utcnow()
|
||||
await sess.flush()
|
||||
await call_action("relations", "detach-child", payload={
|
||||
"parent_type": "page", "parent_id": cal.container_id,
|
||||
"child_type": "calendar", "child_id": cal.id,
|
||||
await call_action("relations", "unrelate", payload={
|
||||
"relation_type": "page->calendar",
|
||||
"from_id": cal.container_id, "to_id": cal.id,
|
||||
})
|
||||
return True
|
||||
|
||||
@@ -108,9 +108,11 @@ 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 call_action("relations", "attach-child", payload={
|
||||
"parent_type": "page", "parent_id": post_id,
|
||||
"child_type": "calendar", "child_id": existing.id,
|
||||
await call_action("relations", "relate", payload={
|
||||
"relation_type": "page->calendar",
|
||||
"from_id": post_id, "to_id": existing.id,
|
||||
"label": existing.name,
|
||||
"metadata": {"slug": existing.slug},
|
||||
})
|
||||
return existing
|
||||
raise CalendarError(f'Calendar with slug "{slug}" already exists for post {post_id}.')
|
||||
@@ -118,9 +120,11 @@ async def create_calendar(sess: AsyncSession, post_id: int, name: str) -> Calend
|
||||
cal = Calendar(container_type="page", container_id=post_id, name=name, slug=slug)
|
||||
sess.add(cal)
|
||||
await sess.flush()
|
||||
await call_action("relations", "attach-child", payload={
|
||||
"parent_type": "page", "parent_id": post_id,
|
||||
"child_type": "calendar", "child_id": cal.id,
|
||||
await call_action("relations", "relate", payload={
|
||||
"relation_type": "page->calendar",
|
||||
"from_id": post_id, "to_id": cal.id,
|
||||
"label": cal.name,
|
||||
"metadata": {"slug": cal.slug},
|
||||
})
|
||||
return cal
|
||||
|
||||
|
||||
@@ -78,16 +78,17 @@ def register():
|
||||
result = await g.s.execute(stmt)
|
||||
day_slots = list(result.scalars())
|
||||
|
||||
# Fetch container nav from market (skip calendar — we're on a calendar page)
|
||||
# Fetch container nav from relations (exclude calendar — we're on a calendar page)
|
||||
container_nav_html = ""
|
||||
post_data = getattr(g, "post_data", None)
|
||||
if post_data:
|
||||
post_id = post_data["post"]["id"]
|
||||
post_slug = post_data["post"]["slug"]
|
||||
container_nav_html = await fetch_fragment("market", "container-nav", params={
|
||||
container_nav_html = await fetch_fragment("relations", "container-nav", params={
|
||||
"container_type": "page",
|
||||
"container_id": str(post_id),
|
||||
"post_slug": post_slug,
|
||||
"exclude": "page->calendar",
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -141,10 +142,11 @@ def register():
|
||||
post_slug = post_data["post"]["slug"]
|
||||
|
||||
if widget_domain == "market":
|
||||
html = await fetch_fragment("market", "container-nav", params={
|
||||
html = await fetch_fragment("relations", "container-nav", params={
|
||||
"container_type": "page",
|
||||
"container_id": str(post_id),
|
||||
"post_slug": post_slug,
|
||||
"exclude": "page->calendar",
|
||||
})
|
||||
return await make_response(html or "")
|
||||
abort(404)
|
||||
|
||||
Reference in New Issue
Block a user