Replace HTTP API and MarketPlace imports with service calls
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 42s

Calendar entries route now uses services.cart.cart_summary() instead of
internal HTTP API call to cart app. Market CRUD delegates to
services.market.create_marketplace() / soft_delete_marketplace().
Updates shared submodule.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-19 05:44:18 +00:00
parent a03fa90463
commit 2527c854cb
3 changed files with 16 additions and 47 deletions

View File

@@ -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")

View File

@@ -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)

2
shared

Submodule shared updated: 9cba422aa9...b3a0e9922a