diff --git a/bp/menu_items/services/menu_items.py b/bp/menu_items/services/menu_items.py index 5622dbd..60dfbe2 100644 --- a/bp/menu_items/services/menu_items.py +++ b/bp/menu_items/services/menu_items.py @@ -4,6 +4,7 @@ from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy import select, func from glue.models.menu_node import MenuNode from models.ghost_content import Post +from glue.services.relationships import attach_child, detach_child class MenuItemError(ValueError): @@ -79,6 +80,7 @@ async def create_menu_item( ) session.add(menu_node) await session.flush() + await attach_child(session, "page", post_id, "menu_node", menu_node.id) return menu_node @@ -117,6 +119,7 @@ async def update_menu_item( if existing: raise MenuItemError("Menu item for this page already exists.") + old_post_id = menu_node.container_id menu_node.container_id = post_id menu_node.label = post.title menu_node.slug = post.slug @@ -127,6 +130,10 @@ async def update_menu_item( await session.flush() + if post_id is not None and post_id != old_post_id: + await detach_child(session, "page", old_post_id, "menu_node", menu_node.id) + await attach_child(session, "page", post_id, "menu_node", menu_node.id) + return menu_node @@ -138,6 +145,7 @@ async def delete_menu_item(session: AsyncSession, item_id: int) -> bool: menu_node.deleted_at = func.now() await session.flush() + await detach_child(session, "page", menu_node.container_id, "menu_node", menu_node.id) return True diff --git a/bp/post/admin/routes.py b/bp/post/admin/routes.py index 0832253..9e51b62 100644 --- a/bp/post/admin/routes.py +++ b/bp/post/admin/routes.py @@ -82,6 +82,8 @@ def register(): pc = PageConfig(container_type="page", container_id=post_id, features={}) g.s.add(pc) await g.s.flush() + from glue.services.relationships import attach_child + await attach_child(g.s, "page", post_id, "page_config", pc.id) # Parse request body body = await request.get_json() @@ -144,6 +146,8 @@ def register(): pc = PageConfig(container_type="page", container_id=post_id, features={}) g.s.add(pc) await g.s.flush() + from glue.services.relationships import attach_child + await attach_child(g.s, "page", post_id, "page_config", pc.id) form = await request.form merchant_code = (form.get("merchant_code") or "").strip() diff --git a/bp/post/services/markets.py b/bp/post/services/markets.py index b432f86..a28989d 100644 --- a/bp/post/services/markets.py +++ b/bp/post/services/markets.py @@ -10,6 +10,7 @@ from market.models.market_place import MarketPlace from models.ghost_content import Post from cart.models.page_config import PageConfig from shared.browser.app.utils import utcnow +from glue.services.relationships import attach_child, detach_child class MarketError(ValueError): @@ -58,12 +59,14 @@ async def create_market(sess: AsyncSession, post_id: int, name: str) -> MarketPl existing.deleted_at = None # revive existing.name = name await sess.flush() + await attach_child(sess, "page", post_id, "market", existing.id) return existing raise MarketError(f'Market with slug "{slug}" already exists for this page.') market = MarketPlace(container_type="page", container_id=post_id, name=name, slug=slug) sess.add(market) await sess.flush() + await attach_child(sess, "page", post_id, "market", market.id) return market @@ -86,4 +89,5 @@ async def soft_delete_market(sess: AsyncSession, post_slug: str, market_slug: st market.deleted_at = utcnow() await sess.flush() + await detach_child(sess, "page", market.container_id, "market", market.id) return True