Add attach/detach glue calls to calendar and market CRUD
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 48s

Wire up ContainerRelation tracking via attach_child/detach_child in:
- calendars: create (including revive), soft_delete
- markets: create (including revive), soft_delete

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-14 09:52:13 +00:00
parent ee93832db0
commit fca0950cd1
2 changed files with 8 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from models.calendars import Calendar
from blog.models.ghost_content import Post # for FK existence checks
from glue.services.relationships import attach_child, detach_child
import unicodedata
import re
@@ -66,6 +67,7 @@ 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)
return True
async def create_calendar(sess: AsyncSession, post_id: int, name: str) -> Calendar:
@@ -98,12 +100,14 @@ 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)
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)
return cal

View File

@@ -9,6 +9,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from market.models.market_place import MarketPlace
from blog.models.ghost_content import Post
from shared.browser.app.utils import utcnow
from glue.services.relationships import attach_child, detach_child
class MarketError(ValueError):
@@ -55,12 +56,14 @@ async def create_market(sess: AsyncSession, post_id: int, name: str) -> MarketPl
existing.deleted_at = None
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
@@ -83,4 +86,5 @@ async def soft_delete(sess: AsyncSession, post_slug: str, market_slug: str) -> b
market.deleted_at = utcnow()
await sess.flush()
await detach_child(sess, "page", market.container_id, "market", market.id)
return True