Some checks failed
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>
59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
# app/modules/analytics/routes/api/store.py
|
|
"""
|
|
Store Analytics API
|
|
|
|
Store Context: Uses token_store_id from JWT token (authenticated store API pattern).
|
|
The get_current_store_api dependency guarantees token_store_id is present.
|
|
|
|
Feature Requirements:
|
|
- basic_reports: Basic analytics (Essential tier)
|
|
- analytics_dashboard: Advanced analytics (Business tier)
|
|
"""
|
|
|
|
import logging
|
|
|
|
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.api.deps import get_current_store_api, get_db, require_module_access
|
|
from app.modules.analytics.schemas import (
|
|
StoreAnalyticsCatalog,
|
|
StoreAnalyticsImports,
|
|
StoreAnalyticsInventory,
|
|
StoreAnalyticsResponse,
|
|
)
|
|
from app.modules.analytics.services import stats_service
|
|
from app.modules.billing.dependencies.feature_gate import RequireFeature
|
|
from app.modules.enums import FrontendType
|
|
from app.modules.tenancy.models import User
|
|
|
|
router = APIRouter(
|
|
prefix="/analytics",
|
|
dependencies=[Depends(require_module_access("analytics", FrontendType.STORE))],
|
|
)
|
|
router = router # Alias for discovery
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@router.get("", response_model=StoreAnalyticsResponse)
|
|
def get_store_analytics(
|
|
period: str = Query("30d", description="Time period: 7d, 30d, 90d, 1y"),
|
|
current_user: User = Depends(get_current_store_api),
|
|
db: Session = Depends(get_db),
|
|
_: None = Depends(RequireFeature("basic_reports", "analytics_dashboard")),
|
|
):
|
|
"""Get store analytics data for specified time period."""
|
|
data = stats_service.get_store_analytics(db, current_user.token_store_id, period)
|
|
|
|
return StoreAnalyticsResponse(
|
|
period=data["period"],
|
|
start_date=data["start_date"],
|
|
imports=StoreAnalyticsImports(count=data["imports"]["count"]),
|
|
catalog=StoreAnalyticsCatalog(
|
|
products_added=data["catalog"]["products_added"]
|
|
),
|
|
inventory=StoreAnalyticsInventory(
|
|
total_locations=data["inventory"]["total_locations"]
|
|
),
|
|
)
|