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:
2026-02-28 09:24:52 +00:00
parent 53c4a0a1e0
commit d2f1da4944
9 changed files with 65 additions and 70 deletions

View File

@@ -103,7 +103,7 @@ def register(url_prefix, title):
from shared.infrastructure.cart_identity import current_cart_identity
from shared.infrastructure.data_client import fetch_data
from shared.contracts.dtos import CartSummaryDTO, dto_from_dict
from shared.infrastructure.fragments import fetch_fragment, fetch_fragments
from shared.infrastructure.fragments import fetch_fragment
p_data = await _post_data("home", g.s, include_drafts=False)
if not p_data:
@@ -116,22 +116,12 @@ def register(url_prefix, title):
db_post_id = p_data["post"]["id"]
post_slug = p_data["post"]["slug"]
# Fetch container nav fragments from events + market
paginate_url = url_for(
'blog.post.widget_paginate',
slug=post_slug, widget_domain='calendar',
)
nav_params = {
# Fetch container nav from relations service
container_nav_html = await fetch_fragment("relations", "container-nav", params={
"container_type": "page",
"container_id": str(db_post_id),
"post_slug": post_slug,
"paginate_url": paginate_url,
}
events_nav_html, market_nav_html = await fetch_fragments([
("events", "container-nav", nav_params),
("market", "container-nav", nav_params),
])
container_nav_html = events_nav_html + market_nav_html
})
ctx = {
**p_data,

View File

@@ -80,9 +80,11 @@ async def create_menu_item(
)
session.add(menu_node)
await session.flush()
await call_action("relations", "attach-child", payload={
"parent_type": "page", "parent_id": post_id,
"child_type": "menu_node", "child_id": menu_node.id,
await call_action("relations", "relate", payload={
"relation_type": "page->menu_node",
"from_id": post_id, "to_id": menu_node.id,
"label": post.title,
"metadata": {"slug": post.slug},
})
return menu_node
@@ -134,13 +136,15 @@ async def update_menu_item(
await session.flush()
if post_id is not None and post_id != old_post_id:
await call_action("relations", "detach-child", payload={
"parent_type": "page", "parent_id": old_post_id,
"child_type": "menu_node", "child_id": menu_node.id,
await call_action("relations", "unrelate", payload={
"relation_type": "page->menu_node",
"from_id": old_post_id, "to_id": menu_node.id,
})
await call_action("relations", "attach-child", payload={
"parent_type": "page", "parent_id": post_id,
"child_type": "menu_node", "child_id": menu_node.id,
await call_action("relations", "relate", payload={
"relation_type": "page->menu_node",
"from_id": post_id, "to_id": menu_node.id,
"label": post.title,
"metadata": {"slug": post.slug},
})
return menu_node
@@ -154,9 +158,9 @@ async def delete_menu_item(session: AsyncSession, item_id: int) -> bool:
menu_node.deleted_at = func.now()
await session.flush()
await call_action("relations", "detach-child", payload={
"parent_type": "page", "parent_id": menu_node.container_id,
"child_type": "menu_node", "child_id": menu_node.id,
await call_action("relations", "unrelate", payload={
"relation_type": "page->menu_node",
"from_id": menu_node.container_id, "to_id": menu_node.id,
})
return True

View File

@@ -13,7 +13,7 @@ from .services.post_data import post_data
from shared.infrastructure.data_client import fetch_data
from shared.infrastructure.actions import call_action
from shared.contracts.dtos import CartSummaryDTO, dto_from_dict
from shared.infrastructure.fragments import fetch_fragment, fetch_fragments
from shared.infrastructure.fragments import fetch_fragment
from shared.browser.app.redis_cacher import cache_page, clear_cache
@@ -69,22 +69,12 @@ def register():
db_post_id = (g.post_data.get("post") or {}).get("id")
post_slug = (g.post_data.get("post") or {}).get("slug", "")
# Fetch container nav fragments from events + market
paginate_url = url_for(
'blog.post.widget_paginate',
slug=post_slug, widget_domain='calendar',
)
nav_params = {
# Fetch container nav from relations service
container_nav_html = await fetch_fragment("relations", "container-nav", params={
"container_type": "page",
"container_id": str(db_post_id),
"post_slug": post_slug,
"paginate_url": paginate_url,
}
events_nav_html, market_nav_html = await fetch_fragments([
("events", "container-nav", nav_params),
("market", "container-nav", nav_params),
])
container_nav_html = events_nav_html + market_nav_html
})
ctx = {
**p_data,

View File

@@ -7,7 +7,6 @@ from sqlalchemy.ext.asyncio import AsyncSession
from shared.contracts.dtos import MarketPlaceDTO
from shared.infrastructure.actions import call_action, ActionError
from shared.infrastructure.data_client import fetch_data
from shared.services.registry import services
@@ -41,11 +40,11 @@ async def create_market(sess: AsyncSession, post_id: int, name: str) -> MarketPl
if not post.is_page:
raise MarketError("Markets can only be created on pages, not posts.")
raw_pc = await fetch_data("blog", "page-config",
params={"container_type": "page", "container_id": post_id},
required=False)
if raw_pc is None or not (raw_pc.get("features") or {}).get("market"):
raise MarketError("Market feature is not enabled for this page. Enable it in page settings first.")
check = await call_action("relations", "can-relate", payload={
"relation_type": "page->market", "from_id": post_id,
})
if not check.get("allowed"):
raise MarketError(check.get("reason", "Cannot create market for this page."))
try:
result = await call_action("market", "create-marketplace", payload={