Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled
Phase 1 - Relations service (internal): owns ContainerRelation, exposes get-children data + attach/detach-child actions. Retargeted events, blog, market callers from cart to relations. Phase 2 - Likes service (internal): unified Like model replaces ProductLike and PostLike with generic target_type/target_slug/target_id. Exposes is-liked, liked-slugs, liked-ids data + toggle action. Phase 3 - PageConfig → blog: moved ownership to blog with direct DB queries, removed proxy endpoints from cart. Phase 4 - Orders service (public): owns Order/OrderItem + SumUp checkout flow. Cart checkout now delegates to orders via create-order action. Webhook/return routes and reconciliation moved to orders. Phase 5 - Infrastructure: docker-compose, deploy.sh, Dockerfiles updated for all 3 new services. Added orders_url helper and factory model imports. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
97 lines
3.3 KiB
Python
97 lines
3.3 KiB
Python
"""Blog app action endpoints.
|
|
|
|
Exposes write operations at ``/internal/actions/<action_name>`` for
|
|
cross-app callers via the internal action client.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from quart import Blueprint, g, jsonify, request
|
|
|
|
from shared.infrastructure.actions import ACTION_HEADER
|
|
|
|
|
|
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
|
|
from shared.infrastructure.internal_auth import validate_internal_request
|
|
if not validate_internal_request():
|
|
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 or {"ok": True})
|
|
|
|
# --- update-page-config ---
|
|
async def _update_page_config():
|
|
"""Create or update a PageConfig (page_configs now lives in db_blog)."""
|
|
from shared.models.page_config import PageConfig
|
|
from sqlalchemy import select
|
|
from sqlalchemy.orm.attributes import flag_modified
|
|
|
|
data = await request.get_json(force=True)
|
|
container_type = data.get("container_type", "page")
|
|
container_id = data.get("container_id")
|
|
if container_id is None:
|
|
return {"error": "container_id required"}, 400
|
|
|
|
pc = (await g.s.execute(
|
|
select(PageConfig).where(
|
|
PageConfig.container_type == container_type,
|
|
PageConfig.container_id == container_id,
|
|
)
|
|
)).scalar_one_or_none()
|
|
|
|
if pc is None:
|
|
pc = PageConfig(
|
|
container_type=container_type,
|
|
container_id=container_id,
|
|
features=data.get("features", {}),
|
|
)
|
|
g.s.add(pc)
|
|
await g.s.flush()
|
|
|
|
if "features" in data:
|
|
features = dict(pc.features or {})
|
|
for key, val in data["features"].items():
|
|
if isinstance(val, bool):
|
|
features[key] = val
|
|
elif val in ("true", "1", "on"):
|
|
features[key] = True
|
|
elif val in ("false", "0", "off", None):
|
|
features[key] = False
|
|
pc.features = features
|
|
flag_modified(pc, "features")
|
|
|
|
if "sumup_merchant_code" in data:
|
|
pc.sumup_merchant_code = data["sumup_merchant_code"] or None
|
|
if "sumup_checkout_prefix" in data:
|
|
pc.sumup_checkout_prefix = data["sumup_checkout_prefix"] or None
|
|
if "sumup_api_key" in data:
|
|
pc.sumup_api_key = data["sumup_api_key"] or None
|
|
|
|
await g.s.flush()
|
|
|
|
return {
|
|
"id": pc.id,
|
|
"container_type": pc.container_type,
|
|
"container_id": pc.container_id,
|
|
"features": pc.features or {},
|
|
"sumup_merchant_code": pc.sumup_merchant_code,
|
|
"sumup_checkout_prefix": pc.sumup_checkout_prefix,
|
|
"sumup_configured": bool(pc.sumup_api_key),
|
|
}
|
|
|
|
_handlers["update-page-config"] = _update_page_config
|
|
|
|
return bp
|