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:
@@ -15,6 +15,7 @@ tenancy_module = ModuleDefinition(
|
||||
description="Platform, company, vendor, and admin user management. Required for multi-tenant operation.",
|
||||
version="1.0.0",
|
||||
is_core=True,
|
||||
is_self_contained=True,
|
||||
features=[
|
||||
"platform_management",
|
||||
"company_management",
|
||||
@@ -32,6 +33,10 @@ tenancy_module = ModuleDefinition(
|
||||
"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"]
|
||||
|
||||
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"]
|
||||
82
app/modules/tenancy/routes/api/vendor.py
Normal file
82
app/modules/tenancy/routes/api/vendor.py
Normal file
@@ -0,0 +1,82 @@
|
||||
# app/modules/tenancy/routes/api/vendor.py
|
||||
"""
|
||||
Tenancy module vendor API routes.
|
||||
|
||||
Provides public vendor information lookup for:
|
||||
- Vendor login pages to display branding
|
||||
- Public vendor profile lookup
|
||||
|
||||
These endpoints do NOT require authentication - they provide
|
||||
public information about vendors.
|
||||
"""
|
||||
|
||||
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 # noqa: mod-004
|
||||
from models.schema.vendor import VendorDetailResponse
|
||||
|
||||
vendor_router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@vendor_router.get("/info/{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,
|
||||
)
|
||||
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
|
||||
Reference in New Issue
Block a user