Replace HTTP API and MarketPlace imports with service calls
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 42s
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:
@@ -219,10 +219,14 @@ def register():
|
|||||||
select(sa_func.count()).select_from(CalendarEntry).where(*cal_filters)
|
select(sa_func.count()).select_from(CalendarEntry).where(*cal_filters)
|
||||||
) or 0
|
) or 0
|
||||||
|
|
||||||
# Get product cart count from API (committed data only, which is fine)
|
# Get product cart count via service (same DB, no HTTP needed)
|
||||||
from shared.infrastructure.internal_api import get as api_get
|
from shared.infrastructure.cart_identity import current_cart_identity
|
||||||
cart_data = await api_get("cart", "/internal/cart/summary", forward_session=True)
|
from shared.services.registry import services
|
||||||
product_count = cart_data.get("count", 0) if cart_data else 0
|
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
|
total_count = product_count + cal_count
|
||||||
|
|
||||||
html = await render_template("_types/day/_main_panel.html")
|
html = await render_template("_types/day/_main_panel.html")
|
||||||
|
|||||||
@@ -3,13 +3,10 @@ from __future__ import annotations
|
|||||||
import re
|
import re
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
from sqlalchemy import select
|
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
from shared.models.market_place import MarketPlace
|
from shared.contracts.dtos import MarketPlaceDTO
|
||||||
from shared.browser.app.utils import utcnow
|
|
||||||
from shared.services.registry import services
|
from shared.services.registry import services
|
||||||
from shared.services.relationships import attach_child, detach_child
|
|
||||||
|
|
||||||
|
|
||||||
class MarketError(ValueError):
|
class MarketError(ValueError):
|
||||||
@@ -29,7 +26,7 @@ def slugify(value: str, max_len: int = 255) -> str:
|
|||||||
return value or "market"
|
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.
|
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,
|
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:
|
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.")
|
||||||
|
|
||||||
# Look for existing (including soft-deleted)
|
try:
|
||||||
existing = (await sess.execute(
|
return await services.market.create_marketplace(sess, "page", post_id, name, slug)
|
||||||
select(MarketPlace).where(MarketPlace.container_type == "page", MarketPlace.container_id == post_id, MarketPlace.slug == slug)
|
except ValueError as e:
|
||||||
)).scalar_one_or_none()
|
raise MarketError(str(e)) from e
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
async def soft_delete(sess: AsyncSession, post_slug: str, market_slug: str) -> bool:
|
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:
|
if not post:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
market = (
|
return await services.market.soft_delete_marketplace(sess, "page", post.id, market_slug)
|
||||||
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
|
|
||||||
|
|||||||
2
shared
2
shared
Submodule shared updated: 9cba422aa9...b3a0e9922a
Reference in New Issue
Block a user