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>
67 lines
2.0 KiB
Python
67 lines
2.0 KiB
Python
"""Market app action endpoints.
|
|
|
|
Exposes write operations at ``/internal/actions/<action_name>`` for
|
|
cross-app callers (blog, events) via the internal action client.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from quart import Blueprint, g, jsonify, request
|
|
|
|
from shared.infrastructure.actions import ACTION_HEADER
|
|
from shared.services.registry import services
|
|
|
|
|
|
def register() -> Blueprint:
|
|
bp = Blueprint("actions", __name__, url_prefix="/internal/actions")
|
|
|
|
@bp.before_request
|
|
async def _require_action_header():
|
|
if not request.headers.get(ACTION_HEADER):
|
|
return jsonify({"error": "forbidden"}), 403
|
|
|
|
_handlers: dict[str, object] = {}
|
|
|
|
@bp.post("/<action_name>")
|
|
async def handle_action(action_name: str):
|
|
handler = _handlers.get(action_name)
|
|
if handler is None:
|
|
return jsonify({"error": "unknown action"}), 404
|
|
result = await handler()
|
|
return jsonify(result)
|
|
|
|
# --- create-marketplace ---
|
|
async def _create_marketplace():
|
|
data = await request.get_json()
|
|
mp = await services.market.create_marketplace(
|
|
g.s,
|
|
data["container_type"],
|
|
data["container_id"],
|
|
data["name"],
|
|
data["slug"],
|
|
)
|
|
return {
|
|
"id": mp.id,
|
|
"container_type": mp.container_type,
|
|
"container_id": mp.container_id,
|
|
"name": mp.name,
|
|
"slug": mp.slug,
|
|
"description": mp.description,
|
|
}
|
|
|
|
_handlers["create-marketplace"] = _create_marketplace
|
|
|
|
# --- soft-delete-marketplace ---
|
|
async def _soft_delete_marketplace():
|
|
data = await request.get_json()
|
|
deleted = await services.market.soft_delete_marketplace(
|
|
g.s,
|
|
data["container_type"],
|
|
data["container_id"],
|
|
data["slug"],
|
|
)
|
|
return {"deleted": deleted}
|
|
|
|
_handlers["soft-delete-marketplace"] = _soft_delete_marketplace
|
|
|
|
return bp
|