Decouple all cross-app service calls to HTTP endpoints
Replace every direct cross-app services.* call with HTTP-based communication: call_action() for writes, fetch_data() for reads. Each app now registers only its own domain service. Infrastructure: - shared/infrastructure/actions.py — POST client for /internal/actions/ - shared/infrastructure/data_client.py — GET client for /internal/data/ - shared/contracts/dtos.py — dto_to_dict/dto_from_dict serialization Action endpoints (writes): - events: 8 handlers (ticket adjust, claim/confirm, toggle, adopt) - market: 2 handlers (create/soft-delete marketplace) - cart: 1 handler (adopt cart for user) Data endpoints (reads): - blog: 4 (post-by-slug/id, posts-by-ids, search-posts) - events: 10 (pending entries/tickets, entries/tickets for page/order, entry-ids, associated-entries, calendars, visible-entries-for-period) - market: 1 (marketplaces-for-container) - cart: 1 (cart-summary) Service registration cleanup: - blog→blog+federation, events→calendar+federation, market→market+federation, cart→cart only, federation→federation only, account→nothing - Stubs reduced to minimal StubFederationService Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,9 @@ from __future__ import annotations
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from shared.infrastructure.actions import call_action, ActionError
|
||||
from shared.infrastructure.data_client import fetch_data
|
||||
from shared.contracts.dtos import CalendarEntryDTO, dto_from_dict
|
||||
from shared.services.registry import services
|
||||
|
||||
|
||||
@@ -18,10 +21,13 @@ async def toggle_entry_association(
|
||||
if not post:
|
||||
return False, "Post not found"
|
||||
|
||||
is_associated = await services.calendar.toggle_entry_post(
|
||||
session, entry_id, "post", post_id,
|
||||
)
|
||||
return is_associated, None
|
||||
try:
|
||||
result = await call_action("events", "toggle-entry-post", payload={
|
||||
"entry_id": entry_id, "content_type": "post", "content_id": post_id,
|
||||
})
|
||||
return result.get("is_associated", False), None
|
||||
except ActionError as e:
|
||||
return False, str(e)
|
||||
|
||||
|
||||
async def get_post_entry_ids(
|
||||
@@ -32,7 +38,10 @@ async def get_post_entry_ids(
|
||||
Get all entry IDs associated with this post.
|
||||
Returns a set of entry IDs.
|
||||
"""
|
||||
return await services.calendar.entry_ids_for_content(session, "post", post_id)
|
||||
raw = await fetch_data("events", "entry-ids-for-content",
|
||||
params={"content_type": "post", "content_id": post_id},
|
||||
required=False) or []
|
||||
return set(raw)
|
||||
|
||||
|
||||
async def get_associated_entries(
|
||||
@@ -45,12 +54,14 @@ async def get_associated_entries(
|
||||
Get paginated associated entries for this post.
|
||||
Returns dict with entries (CalendarEntryDTOs), total_count, and has_more.
|
||||
"""
|
||||
entries, has_more = await services.calendar.associated_entries(
|
||||
session, "post", post_id, page,
|
||||
)
|
||||
raw = await fetch_data("events", "associated-entries",
|
||||
params={"content_type": "post", "content_id": post_id, "page": page},
|
||||
required=False) or {"entries": [], "has_more": False}
|
||||
entries = [dto_from_dict(CalendarEntryDTO, e) for e in raw.get("entries", [])]
|
||||
has_more = raw.get("has_more", False)
|
||||
total_count = len(entries) + (page - 1) * per_page
|
||||
if has_more:
|
||||
total_count += 1 # at least one more
|
||||
total_count += 1
|
||||
|
||||
return {
|
||||
"entries": entries,
|
||||
|
||||
@@ -8,6 +8,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from shared.models.page_config import PageConfig
|
||||
from shared.contracts.dtos import MarketPlaceDTO
|
||||
from shared.infrastructure.actions import call_action, ActionError
|
||||
from shared.services.registry import services
|
||||
|
||||
|
||||
@@ -48,8 +49,12 @@ async def create_market(sess: AsyncSession, post_id: int, name: str) -> MarketPl
|
||||
raise MarketError("Market feature is not enabled for this page. Enable it in page settings first.")
|
||||
|
||||
try:
|
||||
return await services.market.create_marketplace(sess, "page", post_id, name, slug)
|
||||
except ValueError as e:
|
||||
result = await call_action("market", "create-marketplace", payload={
|
||||
"container_type": "page", "container_id": post_id,
|
||||
"name": name, "slug": slug,
|
||||
})
|
||||
return MarketPlaceDTO(**result)
|
||||
except ActionError as e:
|
||||
raise MarketError(str(e)) from e
|
||||
|
||||
|
||||
@@ -58,4 +63,10 @@ async def soft_delete_market(sess: AsyncSession, post_slug: str, market_slug: st
|
||||
if not post:
|
||||
return False
|
||||
|
||||
return await services.market.soft_delete_marketplace(sess, "page", post.id, market_slug)
|
||||
try:
|
||||
result = await call_action("market", "soft-delete-marketplace", payload={
|
||||
"container_type": "page", "container_id": post.id, "slug": market_slug,
|
||||
})
|
||||
return result.get("deleted", False)
|
||||
except ActionError:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user