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>
This commit is contained in:
9
app/api/v1/vendor/__init__.py
vendored
9
app/api/v1/vendor/__init__.py
vendored
@@ -24,6 +24,7 @@ Self-contained modules (auto-discovered from app/modules/{module}/routes/api/ven
|
||||
- cms: Content pages management
|
||||
- customers: Customer management
|
||||
- payments: Payment configuration, Stripe connect, transactions
|
||||
- tenancy: Public vendor info lookup
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter
|
||||
@@ -34,7 +35,6 @@ from . import (
|
||||
dashboard,
|
||||
email_settings,
|
||||
email_templates,
|
||||
info,
|
||||
media,
|
||||
messages,
|
||||
notifications,
|
||||
@@ -51,10 +51,6 @@ router = APIRouter()
|
||||
# ============================================================================
|
||||
# These routes return JSON and are mounted at /api/v1/vendor/*
|
||||
|
||||
# IMPORTANT: Specific routes MUST be registered BEFORE catch-all routes
|
||||
# The info.router has GET /{vendor_code} which catches everything,
|
||||
# so it must be registered LAST
|
||||
|
||||
# Authentication (no prefix, specific routes like /auth/login)
|
||||
router.include_router(auth.router, tags=["vendor-auth"])
|
||||
|
||||
@@ -98,7 +94,4 @@ for route_info in get_vendor_api_routes():
|
||||
)
|
||||
|
||||
|
||||
# Vendor info endpoint - MUST BE LAST! Has catch-all GET /{vendor_code}
|
||||
router.include_router(info.router, tags=["vendor-info"])
|
||||
|
||||
__all__ = ["router"]
|
||||
|
||||
79
app/api/v1/vendor/info.py
vendored
79
app/api/v1/vendor/info.py
vendored
@@ -1,79 +0,0 @@
|
||||
# app/api/v1/vendor/info.py
|
||||
"""
|
||||
Vendor information endpoints.
|
||||
|
||||
This module provides:
|
||||
- Public vendor information lookup (no auth required)
|
||||
- Used by vendor login pages to display vendor details
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from fastapi import APIRouter, Depends, Path
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.services.vendor_service import vendor_service
|
||||
from models.schema.vendor import VendorDetailResponse
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@router.get("/{vendor_code}", response_model=VendorDetailResponse)
|
||||
def get_vendor_info(
|
||||
vendor_code: str = Path(..., description="Vendor code"),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Get public vendor information by vendor code.
|
||||
|
||||
This endpoint is used by the vendor login page to display vendor info.
|
||||
No authentication required - this is public information.
|
||||
|
||||
**Use Case:**
|
||||
- Vendor login page loads vendor info to display branding
|
||||
- Shows vendor name, description, logo, etc.
|
||||
|
||||
**Returns only active vendors** to prevent access to disabled accounts.
|
||||
|
||||
Args:
|
||||
vendor_code: The vendor's unique code (e.g., 'WIZAMART')
|
||||
db: Database session
|
||||
|
||||
Returns:
|
||||
VendorResponse: Public vendor information
|
||||
|
||||
Raises:
|
||||
VendorNotFoundException (404): Vendor not found or inactive
|
||||
"""
|
||||
logger.info(f"Public vendor info request: {vendor_code}")
|
||||
|
||||
vendor = vendor_service.get_active_vendor_by_code(db, vendor_code)
|
||||
|
||||
logger.info(f"Vendor info retrieved: {vendor.name} ({vendor.vendor_code})")
|
||||
|
||||
return VendorDetailResponse(
|
||||
# Vendor fields
|
||||
id=vendor.id,
|
||||
vendor_code=vendor.vendor_code,
|
||||
subdomain=vendor.subdomain,
|
||||
name=vendor.name,
|
||||
description=vendor.description,
|
||||
company_id=vendor.company_id,
|
||||
letzshop_csv_url_fr=vendor.letzshop_csv_url_fr,
|
||||
letzshop_csv_url_en=vendor.letzshop_csv_url_en,
|
||||
letzshop_csv_url_de=vendor.letzshop_csv_url_de,
|
||||
is_active=vendor.is_active,
|
||||
is_verified=vendor.is_verified,
|
||||
created_at=vendor.created_at,
|
||||
updated_at=vendor.updated_at,
|
||||
# Company info
|
||||
company_name=vendor.company.name,
|
||||
company_contact_email=vendor.company.contact_email,
|
||||
company_contact_phone=vendor.company.contact_phone,
|
||||
company_website=vendor.company.website,
|
||||
# Owner details (from company)
|
||||
owner_email=vendor.company.owner.email,
|
||||
owner_username=vendor.company.owner.username,
|
||||
)
|
||||
Reference in New Issue
Block a user