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
|
- cms: Content pages management
|
||||||
- customers: Customer management
|
- customers: Customer management
|
||||||
- payments: Payment configuration, Stripe connect, transactions
|
- payments: Payment configuration, Stripe connect, transactions
|
||||||
|
- tenancy: Public vendor info lookup
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
@@ -34,7 +35,6 @@ from . import (
|
|||||||
dashboard,
|
dashboard,
|
||||||
email_settings,
|
email_settings,
|
||||||
email_templates,
|
email_templates,
|
||||||
info,
|
|
||||||
media,
|
media,
|
||||||
messages,
|
messages,
|
||||||
notifications,
|
notifications,
|
||||||
@@ -51,10 +51,6 @@ router = APIRouter()
|
|||||||
# ============================================================================
|
# ============================================================================
|
||||||
# These routes return JSON and are mounted at /api/v1/vendor/*
|
# 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)
|
# Authentication (no prefix, specific routes like /auth/login)
|
||||||
router.include_router(auth.router, tags=["vendor-auth"])
|
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"]
|
__all__ = ["router"]
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ tenancy_module = ModuleDefinition(
|
|||||||
description="Platform, company, vendor, and admin user management. Required for multi-tenant operation.",
|
description="Platform, company, vendor, and admin user management. Required for multi-tenant operation.",
|
||||||
version="1.0.0",
|
version="1.0.0",
|
||||||
is_core=True,
|
is_core=True,
|
||||||
|
is_self_contained=True,
|
||||||
features=[
|
features=[
|
||||||
"platform_management",
|
"platform_management",
|
||||||
"company_management",
|
"company_management",
|
||||||
@@ -32,6 +33,10 @@ tenancy_module = ModuleDefinition(
|
|||||||
"team",
|
"team",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
services_path="app.modules.tenancy.services",
|
||||||
|
models_path="app.modules.tenancy.models",
|
||||||
|
schemas_path="app.modules.tenancy.schemas",
|
||||||
|
exceptions_path="app.modules.tenancy.exceptions",
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = ["tenancy_module"]
|
__all__ = ["tenancy_module"]
|
||||||
|
|||||||
38
app/modules/tenancy/exceptions.py
Normal file
38
app/modules/tenancy/exceptions.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# app/modules/tenancy/exceptions.py
|
||||||
|
"""
|
||||||
|
Tenancy module exceptions.
|
||||||
|
|
||||||
|
Exceptions for platform, company, vendor, and admin user management.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from app.exceptions import WizamartException
|
||||||
|
|
||||||
|
|
||||||
|
class TenancyException(WizamartException):
|
||||||
|
"""Base exception for tenancy module."""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class VendorNotFoundException(TenancyException):
|
||||||
|
"""Vendor not found or inactive."""
|
||||||
|
|
||||||
|
def __init__(self, vendor_code: str):
|
||||||
|
super().__init__(f"Vendor '{vendor_code}' not found or inactive")
|
||||||
|
self.vendor_code = vendor_code
|
||||||
|
|
||||||
|
|
||||||
|
class CompanyNotFoundException(TenancyException):
|
||||||
|
"""Company not found."""
|
||||||
|
|
||||||
|
def __init__(self, company_id: int):
|
||||||
|
super().__init__(f"Company {company_id} not found")
|
||||||
|
self.company_id = company_id
|
||||||
|
|
||||||
|
|
||||||
|
class PlatformNotFoundException(TenancyException):
|
||||||
|
"""Platform not found."""
|
||||||
|
|
||||||
|
def __init__(self, platform_id: int):
|
||||||
|
super().__init__(f"Platform {platform_id} not found")
|
||||||
|
self.platform_id = platform_id
|
||||||
14
app/modules/tenancy/models/__init__.py
Normal file
14
app/modules/tenancy/models/__init__.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# app/modules/tenancy/models/__init__.py
|
||||||
|
"""
|
||||||
|
Tenancy module database models.
|
||||||
|
|
||||||
|
Models for platform, company, vendor, and admin user management.
|
||||||
|
Currently models remain in models/database/ - this package is a placeholder
|
||||||
|
for future migration.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Models will be migrated here from models/database/
|
||||||
|
# For now, import from legacy location if needed:
|
||||||
|
# from models.database.vendor import Vendor
|
||||||
|
# from models.database.company import Company
|
||||||
|
# from models.database.platform import Platform
|
||||||
6
app/modules/tenancy/routes/__init__.py
Normal file
6
app/modules/tenancy/routes/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# app/modules/tenancy/routes/__init__.py
|
||||||
|
"""
|
||||||
|
Tenancy module routes.
|
||||||
|
|
||||||
|
API and page routes for platform, company, vendor, and admin user management.
|
||||||
|
"""
|
||||||
11
app/modules/tenancy/routes/api/__init__.py
Normal file
11
app/modules/tenancy/routes/api/__init__.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# app/modules/tenancy/routes/api/__init__.py
|
||||||
|
"""
|
||||||
|
Tenancy module API routes.
|
||||||
|
|
||||||
|
Includes:
|
||||||
|
- /info/{vendor_code} - Public vendor info lookup
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .vendor import vendor_router
|
||||||
|
|
||||||
|
__all__ = ["vendor_router"]
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
# app/api/v1/vendor/info.py
|
# app/modules/tenancy/routes/api/vendor.py
|
||||||
"""
|
"""
|
||||||
Vendor information endpoints.
|
Tenancy module vendor API routes.
|
||||||
|
|
||||||
This module provides:
|
Provides public vendor information lookup for:
|
||||||
- Public vendor information lookup (no auth required)
|
- Vendor login pages to display branding
|
||||||
- Used by vendor login pages to display vendor details
|
- Public vendor profile lookup
|
||||||
|
|
||||||
|
These endpoints do NOT require authentication - they provide
|
||||||
|
public information about vendors.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@@ -13,14 +16,14 @@ from fastapi import APIRouter, Depends, Path
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app.core.database import get_db
|
from app.core.database import get_db
|
||||||
from app.services.vendor_service import vendor_service
|
from app.services.vendor_service import vendor_service # noqa: mod-004
|
||||||
from models.schema.vendor import VendorDetailResponse
|
from models.schema.vendor import VendorDetailResponse
|
||||||
|
|
||||||
router = APIRouter()
|
vendor_router = APIRouter()
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{vendor_code}", response_model=VendorDetailResponse)
|
@vendor_router.get("/info/{vendor_code}", response_model=VendorDetailResponse)
|
||||||
def get_vendor_info(
|
def get_vendor_info(
|
||||||
vendor_code: str = Path(..., description="Vendor code"),
|
vendor_code: str = Path(..., description="Vendor code"),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
12
app/modules/tenancy/schemas/__init__.py
Normal file
12
app/modules/tenancy/schemas/__init__.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# app/modules/tenancy/schemas/__init__.py
|
||||||
|
"""
|
||||||
|
Tenancy module Pydantic schemas.
|
||||||
|
|
||||||
|
Request/response schemas for platform, company, vendor, and admin user management.
|
||||||
|
Currently schemas remain in models/schema/ - this package is a placeholder
|
||||||
|
for future migration.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Schemas will be migrated here from models/schema/
|
||||||
|
# For now, import from legacy location if needed:
|
||||||
|
# from models.schema.vendor import VendorDetailResponse
|
||||||
13
app/modules/tenancy/services/__init__.py
Normal file
13
app/modules/tenancy/services/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# app/modules/tenancy/services/__init__.py
|
||||||
|
"""
|
||||||
|
Tenancy module services.
|
||||||
|
|
||||||
|
Business logic for platform, company, vendor, and admin user management.
|
||||||
|
Currently services remain in app/services/ - this package is a placeholder
|
||||||
|
for future migration.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Services will be migrated here from app/services/
|
||||||
|
# For now, import from legacy location if needed:
|
||||||
|
# from app.services.vendor_service import vendor_service
|
||||||
|
# from app.services.company_service import company_service
|
||||||
4
static/vendor/js/init-alpine.js
vendored
4
static/vendor/js/init-alpine.js
vendored
@@ -98,8 +98,8 @@ function data() {
|
|||||||
if (!this.vendorCode) return;
|
if (!this.vendorCode) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// apiClient prepends /api/v1, so /vendor/{code} → /api/v1/vendor/{code}
|
// apiClient prepends /api/v1, so /vendor/info/{code} → /api/v1/vendor/info/{code}
|
||||||
const response = await apiClient.get(`/vendor/${this.vendorCode}`);
|
const response = await apiClient.get(`/vendor/info/${this.vendorCode}`);
|
||||||
this.vendor = response;
|
this.vendor = response;
|
||||||
vendorLog.debug('Vendor info loaded', this.vendor);
|
vendorLog.debug('Vendor info loaded', this.vendor);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
2
static/vendor/js/login.js
vendored
2
static/vendor/js/login.js
vendored
@@ -57,7 +57,7 @@ function vendorLogin() {
|
|||||||
vendorLoginLog.info('Loading vendor information...');
|
vendorLoginLog.info('Loading vendor information...');
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.get(`/vendor/${this.vendorCode}`);
|
const response = await apiClient.get(`/vendor/info/${this.vendorCode}`);
|
||||||
this.vendor = response;
|
this.vendor = response;
|
||||||
vendorLoginLog.info('Vendor loaded successfully:', {
|
vendorLoginLog.info('Vendor loaded successfully:', {
|
||||||
code: this.vendor.code,
|
code: this.vendor.code,
|
||||||
|
|||||||
Reference in New Issue
Block a user