Migrate callers from attach-child/detach-child to relate/unrelate API
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m18s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m18s
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:
@@ -103,7 +103,7 @@ def register(url_prefix, title):
|
|||||||
from shared.infrastructure.cart_identity import current_cart_identity
|
from shared.infrastructure.cart_identity import current_cart_identity
|
||||||
from shared.infrastructure.data_client import fetch_data
|
from shared.infrastructure.data_client import fetch_data
|
||||||
from shared.contracts.dtos import CartSummaryDTO, dto_from_dict
|
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)
|
p_data = await _post_data("home", g.s, include_drafts=False)
|
||||||
if not p_data:
|
if not p_data:
|
||||||
@@ -116,22 +116,12 @@ def register(url_prefix, title):
|
|||||||
db_post_id = p_data["post"]["id"]
|
db_post_id = p_data["post"]["id"]
|
||||||
post_slug = p_data["post"]["slug"]
|
post_slug = p_data["post"]["slug"]
|
||||||
|
|
||||||
# Fetch container nav fragments from events + market
|
# Fetch container nav from relations service
|
||||||
paginate_url = url_for(
|
container_nav_html = await fetch_fragment("relations", "container-nav", params={
|
||||||
'blog.post.widget_paginate',
|
|
||||||
slug=post_slug, widget_domain='calendar',
|
|
||||||
)
|
|
||||||
nav_params = {
|
|
||||||
"container_type": "page",
|
"container_type": "page",
|
||||||
"container_id": str(db_post_id),
|
"container_id": str(db_post_id),
|
||||||
"post_slug": post_slug,
|
"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 = {
|
ctx = {
|
||||||
**p_data,
|
**p_data,
|
||||||
|
|||||||
@@ -80,9 +80,11 @@ async def create_menu_item(
|
|||||||
)
|
)
|
||||||
session.add(menu_node)
|
session.add(menu_node)
|
||||||
await session.flush()
|
await session.flush()
|
||||||
await call_action("relations", "attach-child", payload={
|
await call_action("relations", "relate", payload={
|
||||||
"parent_type": "page", "parent_id": post_id,
|
"relation_type": "page->menu_node",
|
||||||
"child_type": "menu_node", "child_id": menu_node.id,
|
"from_id": post_id, "to_id": menu_node.id,
|
||||||
|
"label": post.title,
|
||||||
|
"metadata": {"slug": post.slug},
|
||||||
})
|
})
|
||||||
|
|
||||||
return menu_node
|
return menu_node
|
||||||
@@ -134,13 +136,15 @@ async def update_menu_item(
|
|||||||
await session.flush()
|
await session.flush()
|
||||||
|
|
||||||
if post_id is not None and post_id != old_post_id:
|
if post_id is not None and post_id != old_post_id:
|
||||||
await call_action("relations", "detach-child", payload={
|
await call_action("relations", "unrelate", payload={
|
||||||
"parent_type": "page", "parent_id": old_post_id,
|
"relation_type": "page->menu_node",
|
||||||
"child_type": "menu_node", "child_id": menu_node.id,
|
"from_id": old_post_id, "to_id": menu_node.id,
|
||||||
})
|
})
|
||||||
await call_action("relations", "attach-child", payload={
|
await call_action("relations", "relate", payload={
|
||||||
"parent_type": "page", "parent_id": post_id,
|
"relation_type": "page->menu_node",
|
||||||
"child_type": "menu_node", "child_id": menu_node.id,
|
"from_id": post_id, "to_id": menu_node.id,
|
||||||
|
"label": post.title,
|
||||||
|
"metadata": {"slug": post.slug},
|
||||||
})
|
})
|
||||||
|
|
||||||
return menu_node
|
return menu_node
|
||||||
@@ -154,9 +158,9 @@ async def delete_menu_item(session: AsyncSession, item_id: int) -> bool:
|
|||||||
|
|
||||||
menu_node.deleted_at = func.now()
|
menu_node.deleted_at = func.now()
|
||||||
await session.flush()
|
await session.flush()
|
||||||
await call_action("relations", "detach-child", payload={
|
await call_action("relations", "unrelate", payload={
|
||||||
"parent_type": "page", "parent_id": menu_node.container_id,
|
"relation_type": "page->menu_node",
|
||||||
"child_type": "menu_node", "child_id": menu_node.id,
|
"from_id": menu_node.container_id, "to_id": menu_node.id,
|
||||||
})
|
})
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from .services.post_data import post_data
|
|||||||
from shared.infrastructure.data_client import fetch_data
|
from shared.infrastructure.data_client import fetch_data
|
||||||
from shared.infrastructure.actions import call_action
|
from shared.infrastructure.actions import call_action
|
||||||
from shared.contracts.dtos import CartSummaryDTO, dto_from_dict
|
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
|
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")
|
db_post_id = (g.post_data.get("post") or {}).get("id")
|
||||||
post_slug = (g.post_data.get("post") or {}).get("slug", "")
|
post_slug = (g.post_data.get("post") or {}).get("slug", "")
|
||||||
|
|
||||||
# Fetch container nav fragments from events + market
|
# Fetch container nav from relations service
|
||||||
paginate_url = url_for(
|
container_nav_html = await fetch_fragment("relations", "container-nav", params={
|
||||||
'blog.post.widget_paginate',
|
|
||||||
slug=post_slug, widget_domain='calendar',
|
|
||||||
)
|
|
||||||
nav_params = {
|
|
||||||
"container_type": "page",
|
"container_type": "page",
|
||||||
"container_id": str(db_post_id),
|
"container_id": str(db_post_id),
|
||||||
"post_slug": post_slug,
|
"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 = {
|
ctx = {
|
||||||
**p_data,
|
**p_data,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|||||||
|
|
||||||
from shared.contracts.dtos import MarketPlaceDTO
|
from shared.contracts.dtos import MarketPlaceDTO
|
||||||
from shared.infrastructure.actions import call_action, ActionError
|
from shared.infrastructure.actions import call_action, ActionError
|
||||||
from shared.infrastructure.data_client import fetch_data
|
|
||||||
from shared.services.registry import services
|
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:
|
if not post.is_page:
|
||||||
raise MarketError("Markets can only be created on pages, not posts.")
|
raise MarketError("Markets can only be created on pages, not posts.")
|
||||||
|
|
||||||
raw_pc = await fetch_data("blog", "page-config",
|
check = await call_action("relations", "can-relate", payload={
|
||||||
params={"container_type": "page", "container_id": post_id},
|
"relation_type": "page->market", "from_id": post_id,
|
||||||
required=False)
|
})
|
||||||
if raw_pc is None or not (raw_pc.get("features") or {}).get("market"):
|
if not check.get("allowed"):
|
||||||
raise MarketError("Market feature is not enabled for this page. Enable it in page settings first.")
|
raise MarketError(check.get("reason", "Cannot create market for this page."))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = await call_action("market", "create-marketplace", payload={
|
result = await call_action("market", "create-marketplace", payload={
|
||||||
|
|||||||
@@ -215,16 +215,17 @@ def register():
|
|||||||
ticket_type_id=tt.id,
|
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 = ""
|
container_nav_html = ""
|
||||||
post_data = getattr(g, "post_data", None)
|
post_data = getattr(g, "post_data", None)
|
||||||
if post_data:
|
if post_data:
|
||||||
post_id = post_data["post"]["id"]
|
post_id = post_data["post"]["id"]
|
||||||
post_slug = post_data["post"]["slug"]
|
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_type": "page",
|
||||||
"container_id": str(post_id),
|
"container_id": str(post_id),
|
||||||
"post_slug": post_slug,
|
"post_slug": post_slug,
|
||||||
|
"exclude": "page->calendar",
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -71,9 +71,9 @@ async def soft_delete(sess: AsyncSession, post_slug: str, calendar_slug: str) ->
|
|||||||
|
|
||||||
cal.deleted_at = utcnow()
|
cal.deleted_at = utcnow()
|
||||||
await sess.flush()
|
await sess.flush()
|
||||||
await call_action("relations", "detach-child", payload={
|
await call_action("relations", "unrelate", payload={
|
||||||
"parent_type": "page", "parent_id": cal.container_id,
|
"relation_type": "page->calendar",
|
||||||
"child_type": "calendar", "child_id": cal.id,
|
"from_id": cal.container_id, "to_id": cal.id,
|
||||||
})
|
})
|
||||||
return True
|
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:
|
if existing.deleted_at is not None:
|
||||||
existing.deleted_at = None # revive
|
existing.deleted_at = None # revive
|
||||||
await sess.flush()
|
await sess.flush()
|
||||||
await call_action("relations", "attach-child", payload={
|
await call_action("relations", "relate", payload={
|
||||||
"parent_type": "page", "parent_id": post_id,
|
"relation_type": "page->calendar",
|
||||||
"child_type": "calendar", "child_id": existing.id,
|
"from_id": post_id, "to_id": existing.id,
|
||||||
|
"label": existing.name,
|
||||||
|
"metadata": {"slug": existing.slug},
|
||||||
})
|
})
|
||||||
return existing
|
return existing
|
||||||
raise CalendarError(f'Calendar with slug "{slug}" already exists for post {post_id}.')
|
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)
|
cal = Calendar(container_type="page", container_id=post_id, name=name, slug=slug)
|
||||||
sess.add(cal)
|
sess.add(cal)
|
||||||
await sess.flush()
|
await sess.flush()
|
||||||
await call_action("relations", "attach-child", payload={
|
await call_action("relations", "relate", payload={
|
||||||
"parent_type": "page", "parent_id": post_id,
|
"relation_type": "page->calendar",
|
||||||
"child_type": "calendar", "child_id": cal.id,
|
"from_id": post_id, "to_id": cal.id,
|
||||||
|
"label": cal.name,
|
||||||
|
"metadata": {"slug": cal.slug},
|
||||||
})
|
})
|
||||||
return cal
|
return cal
|
||||||
|
|
||||||
|
|||||||
@@ -78,16 +78,17 @@ def register():
|
|||||||
result = await g.s.execute(stmt)
|
result = await g.s.execute(stmt)
|
||||||
day_slots = list(result.scalars())
|
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 = ""
|
container_nav_html = ""
|
||||||
post_data = getattr(g, "post_data", None)
|
post_data = getattr(g, "post_data", None)
|
||||||
if post_data:
|
if post_data:
|
||||||
post_id = post_data["post"]["id"]
|
post_id = post_data["post"]["id"]
|
||||||
post_slug = post_data["post"]["slug"]
|
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_type": "page",
|
||||||
"container_id": str(post_id),
|
"container_id": str(post_id),
|
||||||
"post_slug": post_slug,
|
"post_slug": post_slug,
|
||||||
|
"exclude": "page->calendar",
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -141,10 +142,11 @@ def register():
|
|||||||
post_slug = post_data["post"]["slug"]
|
post_slug = post_data["post"]["slug"]
|
||||||
|
|
||||||
if widget_domain == "market":
|
if widget_domain == "market":
|
||||||
html = await fetch_fragment("market", "container-nav", params={
|
html = await fetch_fragment("relations", "container-nav", params={
|
||||||
"container_type": "page",
|
"container_type": "page",
|
||||||
"container_id": str(post_id),
|
"container_id": str(post_id),
|
||||||
"post_slug": post_slug,
|
"post_slug": post_slug,
|
||||||
|
"exclude": "page->calendar",
|
||||||
})
|
})
|
||||||
return await make_response(html or "")
|
return await make_response(html or "")
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ def register():
|
|||||||
container_type = request.args.get("container_type", "page")
|
container_type = request.args.get("container_type", "page")
|
||||||
container_id = int(request.args.get("container_id", 0))
|
container_id = int(request.args.get("container_id", 0))
|
||||||
post_slug = request.args.get("post_slug", "")
|
post_slug = request.args.get("post_slug", "")
|
||||||
|
nav_class = request.args.get("nav_class", "")
|
||||||
exclude_raw = request.args.get("exclude", "")
|
exclude_raw = request.args.get("exclude", "")
|
||||||
exclude = set(exclude_raw.split(",")) if exclude_raw else set()
|
exclude = set(exclude_raw.split(",")) if exclude_raw else set()
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ def register():
|
|||||||
name=child.label or "",
|
name=child.label or "",
|
||||||
icon=defn.nav_icon or "",
|
icon=defn.nav_icon or "",
|
||||||
**{
|
**{
|
||||||
"nav-class": "",
|
"nav-class": nav_class,
|
||||||
"relation-type": defn.name,
|
"relation-type": defn.name,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -93,9 +93,11 @@ class SqlMarketService:
|
|||||||
existing.deleted_at = None # revive
|
existing.deleted_at = None # revive
|
||||||
existing.name = name
|
existing.name = name
|
||||||
await session.flush()
|
await session.flush()
|
||||||
await call_action("relations", "attach-child", payload={
|
await call_action("relations", "relate", payload={
|
||||||
"parent_type": container_type, "parent_id": container_id,
|
"relation_type": f"{container_type}->market",
|
||||||
"child_type": "market", "child_id": existing.id,
|
"from_id": container_id, "to_id": existing.id,
|
||||||
|
"label": existing.name,
|
||||||
|
"metadata": {"slug": existing.slug},
|
||||||
})
|
})
|
||||||
return _mp_to_dto(existing)
|
return _mp_to_dto(existing)
|
||||||
raise ValueError(f'Market with slug "{slug}" already exists for this container.')
|
raise ValueError(f'Market with slug "{slug}" already exists for this container.')
|
||||||
@@ -106,9 +108,11 @@ class SqlMarketService:
|
|||||||
)
|
)
|
||||||
session.add(market)
|
session.add(market)
|
||||||
await session.flush()
|
await session.flush()
|
||||||
await call_action("relations", "attach-child", payload={
|
await call_action("relations", "relate", payload={
|
||||||
"parent_type": container_type, "parent_id": container_id,
|
"relation_type": f"{container_type}->market",
|
||||||
"child_type": "market", "child_id": market.id,
|
"from_id": container_id, "to_id": market.id,
|
||||||
|
"label": market.name,
|
||||||
|
"metadata": {"slug": market.slug},
|
||||||
})
|
})
|
||||||
return _mp_to_dto(market)
|
return _mp_to_dto(market)
|
||||||
|
|
||||||
@@ -130,8 +134,8 @@ class SqlMarketService:
|
|||||||
|
|
||||||
market.deleted_at = utcnow()
|
market.deleted_at = utcnow()
|
||||||
await session.flush()
|
await session.flush()
|
||||||
await call_action("relations", "detach-child", payload={
|
await call_action("relations", "unrelate", payload={
|
||||||
"parent_type": container_type, "parent_id": container_id,
|
"relation_type": f"{container_type}->market",
|
||||||
"child_type": "market", "child_id": market.id,
|
"from_id": container_id, "to_id": market.id,
|
||||||
})
|
})
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user