diff --git a/bp/calendar_entries/routes.py b/bp/calendar_entries/routes.py index da09020..b4fdb31 100644 --- a/bp/calendar_entries/routes.py +++ b/bp/calendar_entries/routes.py @@ -219,10 +219,14 @@ def register(): select(sa_func.count()).select_from(CalendarEntry).where(*cal_filters) ) or 0 - # Get product cart count from API (committed data only, which is fine) - from shared.infrastructure.internal_api import get as api_get - cart_data = await api_get("cart", "/internal/cart/summary", forward_session=True) - product_count = cart_data.get("count", 0) if cart_data else 0 + # Get product cart count via service (same DB, no HTTP needed) + from shared.infrastructure.cart_identity import current_cart_identity + from shared.services.registry import services + ident = current_cart_identity() + cart_summary = await services.cart.cart_summary( + g.s, user_id=ident["user_id"], session_id=ident["session_id"], + ) + product_count = cart_summary.count total_count = product_count + cal_count html = await render_template("_types/day/_main_panel.html") diff --git a/bp/markets/services/markets.py b/bp/markets/services/markets.py index 950baa0..7b0890a 100644 --- a/bp/markets/services/markets.py +++ b/bp/markets/services/markets.py @@ -3,13 +3,10 @@ from __future__ import annotations import re import unicodedata -from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession -from shared.models.market_place import MarketPlace -from shared.browser.app.utils import utcnow +from shared.contracts.dtos import MarketPlaceDTO from shared.services.registry import services -from shared.services.relationships import attach_child, detach_child class MarketError(ValueError): @@ -29,7 +26,7 @@ def slugify(value: str, max_len: int = 255) -> str: return value or "market" -async def create_market(sess: AsyncSession, post_id: int, name: str) -> MarketPlace: +async def create_market(sess: AsyncSession, post_id: int, name: str) -> MarketPlaceDTO: """ Create a market for a page. Name must be unique per page. If a market with the same (post_id, slug) exists but is soft-deleted, @@ -46,25 +43,10 @@ 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.") - # Look for existing (including soft-deleted) - existing = (await sess.execute( - select(MarketPlace).where(MarketPlace.container_type == "page", MarketPlace.container_id == post_id, MarketPlace.slug == slug) - )).scalar_one_or_none() - - if existing: - if existing.deleted_at is not None: - 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 + try: + return await services.market.create_marketplace(sess, "page", post_id, name, slug) + except ValueError as e: + raise MarketError(str(e)) from e async def soft_delete(sess: AsyncSession, post_slug: str, market_slug: str) -> bool: @@ -72,21 +54,4 @@ async def soft_delete(sess: AsyncSession, post_slug: str, market_slug: str) -> b if not post: return False - market = ( - await sess.execute( - select(MarketPlace).where( - MarketPlace.container_type == "page", - MarketPlace.container_id == post.id, - MarketPlace.slug == market_slug, - MarketPlace.deleted_at.is_(None), - ) - ) - ).scalar_one_or_none() - - if not market: - return False - - market.deleted_at = utcnow() - await sess.flush() - await detach_child(sess, "page", market.container_id, "market", market.id) - return True + return await services.market.soft_delete_marketplace(sess, "page", post.id, market_slug) diff --git a/shared b/shared index 9cba422..b3a0e99 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit 9cba422aa9c072db4bbb2662315d66ea011bd19e +Subproject commit b3a0e9922ac403caf54805b13fff652503b5d07d