Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled
Split from coop monolith. Includes: - Market/browse/product blueprints - Product sync API - Suma scraping pipeline - Templates for market, browse, and product views - Dockerfile and CI workflow for independent deployment
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from quart import g
|
|
|
|
from shared.factory import create_base_app
|
|
from config import config
|
|
|
|
from suma_browser.app.bp import register_market_bp
|
|
|
|
|
|
async def market_context() -> dict:
|
|
"""
|
|
Market app context processor.
|
|
|
|
- menu_items: fetched from coop internal API
|
|
- cart_count/cart_total: fetched from cart internal API
|
|
"""
|
|
from shared.context import base_context
|
|
from shared.internal_api import get as api_get, dictobj
|
|
|
|
ctx = await base_context()
|
|
|
|
# Menu items from coop API (wrapped for attribute access in templates)
|
|
menu_data = await api_get("coop", "/internal/menu-items")
|
|
ctx["menu_items"] = dictobj(menu_data) if menu_data else []
|
|
|
|
# Cart data from cart API
|
|
cart_data = await api_get("cart", "/internal/cart/summary", forward_session=True)
|
|
if cart_data:
|
|
ctx["cart_count"] = cart_data.get("count", 0)
|
|
ctx["cart_total"] = cart_data.get("total", 0)
|
|
else:
|
|
ctx["cart_count"] = 0
|
|
ctx["cart_total"] = 0
|
|
|
|
return ctx
|
|
|
|
|
|
def create_app() -> "Quart":
|
|
app = create_base_app("market", context_fn=market_context)
|
|
|
|
# Market blueprint at root (was /market in monolith)
|
|
app.register_blueprint(
|
|
register_market_bp(
|
|
url_prefix="/",
|
|
title=config()["coop_title"],
|
|
),
|
|
url_prefix="/",
|
|
)
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|