Files
orion/app/api/v1/vendor/__init__.py
Samir Boulahtit 23d59492b7 refactor: move vendor info endpoint to tenancy module
MIGRATION:
- Move app/api/v1/vendor/info.py to app/modules/tenancy/routes/api/vendor.py
- Change endpoint path from GET /{vendor_code} to GET /info/{vendor_code}
- Remove catch-all route ordering dependency

TENANCY MODULE SETUP:
- Mark tenancy module as is_self_contained=True
- Add routes/api/vendor.py with vendor_router
- Add exceptions.py with TenancyException hierarchy
- Add placeholder __init__.py files for services, models, schemas

FRONTEND UPDATES:
- Update static/vendor/js/login.js to use new /vendor/info/{vendor_code} path
- Update static/vendor/js/init-alpine.js to use new /vendor/info/{vendor_code} path

The new path is more explicit and eliminates the need for catch-all route
ordering in the vendor router aggregation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 14:41:05 +01:00

98 lines
3.4 KiB
Python

# app/api/v1/vendor/__init__.py
"""
Vendor API router aggregation.
This module aggregates all vendor-related JSON API endpoints.
IMPORTANT:
- This router is for JSON API endpoints only
- HTML page routes are mounted separately in main.py at /vendor/*
- Do NOT include pages.router here - it causes route conflicts
MODULE SYSTEM:
Routes can be module-gated using require_module_access() dependency.
For multi-tenant apps, module enablement is checked at request time
based on platform context (not at route registration time).
Self-contained modules (auto-discovered from app/modules/{module}/routes/api/vendor.py):
- analytics: Vendor analytics and reporting
- billing: Subscription tiers, vendor billing, checkout, add-ons, features, usage
- inventory: Stock management, inventory tracking
- orders: Order management, fulfillment, exceptions, invoices
- marketplace: Letzshop integration, product sync, onboarding
- catalog: Vendor product catalog management
- cms: Content pages management
- customers: Customer management
- payments: Payment configuration, Stripe connect, transactions
- tenancy: Public vendor info lookup
"""
from fastapi import APIRouter
# Import all sub-routers (legacy routes that haven't been migrated to modules)
from . import (
auth,
dashboard,
email_settings,
email_templates,
media,
messages,
notifications,
profile,
settings,
team,
)
# Create vendor router
router = APIRouter()
# ============================================================================
# JSON API ROUTES ONLY
# ============================================================================
# These routes return JSON and are mounted at /api/v1/vendor/*
# Authentication (no prefix, specific routes like /auth/login)
router.include_router(auth.router, tags=["vendor-auth"])
# Vendor management (with prefixes: /dashboard/*, /profile/*, /settings/*)
router.include_router(dashboard.router, tags=["vendor-dashboard"])
router.include_router(profile.router, tags=["vendor-profile"])
router.include_router(settings.router, tags=["vendor-settings"])
router.include_router(email_templates.router, tags=["vendor-email-templates"])
router.include_router(email_settings.router, tags=["vendor-email-settings"])
# Business operations (with prefixes: /team/*)
router.include_router(team.router, tags=["vendor-team"])
# Services (with prefixes: /media/*, etc.)
router.include_router(media.router, tags=["vendor-media"])
router.include_router(notifications.router, tags=["vendor-notifications"])
router.include_router(messages.router, tags=["vendor-messages"])
# ============================================================================
# Auto-discovered Module Routes
# ============================================================================
# Routes from self-contained modules are auto-discovered and registered.
# Modules include: billing, inventory, orders, marketplace, cms, customers, payments
# Routes are sorted by priority, so catch-all routes (CMS) come last.
from app.modules.routes import get_vendor_api_routes
for route_info in get_vendor_api_routes():
# Only pass prefix if custom_prefix is set (router already has internal prefix)
if route_info.custom_prefix:
router.include_router(
route_info.router,
prefix=route_info.custom_prefix,
tags=route_info.tags,
)
else:
router.include_router(
route_info.router,
tags=route_info.tags,
)
__all__ = ["router"]