Files
orion/app/modules/tenancy/routes/api/store.py
Samir Boulahtit 30c4593e0f
Some checks failed
CI / ruff (push) Successful in 9s
CI / pytest (push) Has been cancelled
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled
refactor(P6): standardize route variable naming to router
All route files (admin.py, store.py) now export `router` instead of
`admin_router`/`store_router`. Consumer code (definition.py, __init__.py)
imports as `router as admin_router` where distinction is needed.
ModuleDefinition fields remain admin_router/store_router.

64 files changed across all modules. Architecture rules, docs, and
migration plan updated. Added noqa:API001 support to validator for
pre-existing raw dict endpoints now visible with standardized router name.
All 1114 tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-27 11:05:34 +01:00

99 lines
3.3 KiB
Python

# app/modules/tenancy/routes/api/store.py
"""
Tenancy module store API routes.
Aggregates all store tenancy routes:
- /info/{store_code} - Public store info lookup
- /auth/* - Store authentication (login, logout, /me)
- /profile/* - Store profile management
- /team/* - Team member management, roles, permissions
The tenancy module owns identity and organizational hierarchy.
"""
import logging
from fastapi import APIRouter, Depends, Path
from sqlalchemy.orm import Session
from app.core.database import get_db
from app.modules.tenancy.schemas.store import StoreDetailResponse
from app.modules.tenancy.services.store_service import store_service # mod-004
router = APIRouter()
logger = logging.getLogger(__name__)
@router.get("/info/{store_code}", response_model=StoreDetailResponse)
def get_store_info(
store_code: str = Path(..., description="Store code"),
db: Session = Depends(get_db),
):
"""
Get public store information by store code.
This endpoint is used by the store login page to display store info.
No authentication required - this is public information.
**Use Case:**
- Store login page loads store info to display branding
- Shows store name, description, logo, etc.
**Returns only active stores** to prevent access to disabled accounts.
Args:
store_code: The store's unique code (e.g., 'ORION')
db: Database session
Returns:
StoreResponse: Public store information
Raises:
StoreNotFoundException (404): Store not found or inactive
"""
logger.info(f"Public store info request: {store_code}")
store = store_service.get_active_store_by_code(db, store_code)
logger.info(f"Store info retrieved: {store.name} ({store.store_code})")
return StoreDetailResponse(
# Store fields
id=store.id,
store_code=store.store_code,
subdomain=store.subdomain,
name=store.name,
description=store.description,
merchant_id=store.merchant_id,
letzshop_csv_url_fr=store.letzshop_csv_url_fr,
letzshop_csv_url_en=store.letzshop_csv_url_en,
letzshop_csv_url_de=store.letzshop_csv_url_de,
is_active=store.is_active,
is_verified=store.is_verified,
created_at=store.created_at,
updated_at=store.updated_at,
# Merchant info
merchant_name=store.merchant.name,
merchant_contact_email=store.merchant.contact_email,
merchant_contact_phone=store.merchant.contact_phone,
merchant_website=store.merchant.website,
# Owner details (from merchant)
owner_user_id=store.merchant.owner_user_id,
owner_email=store.merchant.owner.email,
owner_username=store.merchant.owner.username,
)
# ============================================================================
# Aggregate Sub-Routers
# ============================================================================
# Include all tenancy store routes (auth, profile, team)
from .store_auth import store_auth_router
from .store_profile import store_profile_router
from .store_team import store_team_router
router.include_router(store_auth_router, tags=["store-auth"])
router.include_router(store_profile_router, tags=["store-profile"])
router.include_router(store_team_router, tags=["store-team"])