Files
mono/market/bp/all_markets/routes.py
giles 3b707ec8a0 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>
2026-02-25 03:01:38 +00:00

80 lines
2.5 KiB
Python

"""
All-markets blueprint — shows markets across ALL pages.
Mounted at / (root of market app). No slug context.
Routes:
GET / — full page with first page of markets
GET /all-markets — HTMX fragment for infinite scroll
"""
from __future__ import annotations
from quart import Blueprint, g, request, render_template, make_response
from shared.browser.app.utils.htmx import is_htmx_request
from shared.infrastructure.data_client import fetch_data
from shared.contracts.dtos import PostDTO, dto_from_dict
from shared.services.registry import services
def register() -> Blueprint:
bp = Blueprint("all_markets", __name__)
async def _load_markets(page, per_page=20):
"""Load all markets + page info for container badges."""
markets, has_more = await services.market.list_marketplaces(
g.s, page=page, per_page=per_page,
)
# Batch-load page info for container_ids
page_info = {}
if markets:
post_ids = list({
m.container_id for m in markets
if m.container_type == "page"
})
if post_ids:
raw_posts = await fetch_data("blog", "posts-by-ids",
params={"ids": ",".join(str(i) for i in post_ids)},
required=False) or []
for raw_p in raw_posts:
p = dto_from_dict(PostDTO, raw_p)
page_info[p.id] = {"title": p.title, "slug": p.slug}
return markets, has_more, page_info
@bp.get("/")
async def index():
page = int(request.args.get("page", 1))
markets, has_more, page_info = await _load_markets(page)
ctx = dict(
markets=markets,
has_more=has_more,
page_info=page_info,
page=page,
)
if is_htmx_request():
html = await render_template("_types/all_markets/_main_panel.html", **ctx)
else:
html = await render_template("_types/all_markets/index.html", **ctx)
return await make_response(html, 200)
@bp.get("/all-markets")
async def markets_fragment():
page = int(request.args.get("page", 1))
markets, has_more, page_info = await _load_markets(page)
html = await render_template(
"_types/all_markets/_cards.html",
markets=markets,
has_more=has_more,
page_info=page_info,
page=page,
)
return await make_response(html, 200)
return bp