112 lines
3.7 KiB
Python
112 lines
3.7 KiB
Python
# app/api/v1/stats.py
|
|
"""
|
|
Statistics endpoints - simplified with service-level exception handling.
|
|
|
|
This module provides classes and functions for:
|
|
- Comprehensive system statistics
|
|
- Marketplace-specific analytics
|
|
- Performance metrics and data insights
|
|
"""
|
|
|
|
import logging
|
|
from typing import List
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.api.deps import get_current_user
|
|
from app.core.database import get_db
|
|
from app.services.stats_service import stats_service
|
|
from models.schemas.stats import MarketplaceStatsResponse, StatsResponse
|
|
from models.database.user import User
|
|
|
|
router = APIRouter()
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@router.get("/stats", response_model=StatsResponse)
|
|
def get_stats(
|
|
db: Session = Depends(get_db), current_user: User = Depends(get_current_user)
|
|
):
|
|
"""Get comprehensive statistics with marketplace data (Protected)."""
|
|
stats_data = stats_service.get_comprehensive_stats(db=db)
|
|
|
|
return StatsResponse(
|
|
total_products=stats_data["total_products"],
|
|
unique_brands=stats_data["unique_brands"],
|
|
unique_categories=stats_data["unique_categories"],
|
|
unique_marketplaces=stats_data["unique_marketplaces"],
|
|
unique_vendors=stats_data["unique_vendors"],
|
|
total_stock_entries=stats_data["total_stock_entries"],
|
|
total_inventory_quantity=stats_data["total_inventory_quantity"],
|
|
)
|
|
|
|
|
|
@router.get("/stats/marketplace", response_model=List[MarketplaceStatsResponse])
|
|
def get_marketplace_stats(
|
|
db: Session = Depends(get_db), current_user: User = Depends(get_current_user)
|
|
):
|
|
"""Get statistics broken down by marketplace (Protected)."""
|
|
marketplace_stats = stats_service.get_marketplace_breakdown_stats(db=db)
|
|
|
|
# app/api/v1/stats.py
|
|
"""
|
|
Statistics endpoints - simplified with service-level exception handling.
|
|
|
|
This module provides classes and functions for:
|
|
- Comprehensive system statistics
|
|
- Marketplace-specific analytics
|
|
- Performance metrics and data insights
|
|
"""
|
|
|
|
import logging
|
|
from typing import List
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.api.deps import get_current_user
|
|
from app.core.database import get_db
|
|
from app.services.stats_service import stats_service
|
|
from models.schemas.stats import MarketplaceStatsResponse, StatsResponse
|
|
from models.database.user import User
|
|
|
|
router = APIRouter()
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@router.get("/stats", response_model=StatsResponse)
|
|
def get_stats(
|
|
db: Session = Depends(get_db), current_user: User = Depends(get_current_user)
|
|
):
|
|
"""Get comprehensive statistics with marketplace data (Protected)."""
|
|
stats_data = stats_service.get_comprehensive_stats(db=db)
|
|
|
|
return StatsResponse(
|
|
total_products=stats_data["total_products"],
|
|
unique_brands=stats_data["unique_brands"],
|
|
unique_categories=stats_data["unique_categories"],
|
|
unique_marketplaces=stats_data["unique_marketplaces"],
|
|
unique_vendors=stats_data["unique_vendors"],
|
|
total_stock_entries=stats_data["total_stock_entries"],
|
|
total_inventory_quantity=stats_data["total_inventory_quantity"],
|
|
)
|
|
|
|
|
|
@router.get("/stats/marketplace", response_model=List[MarketplaceStatsResponse])
|
|
def get_marketplace_stats(
|
|
db: Session = Depends(get_db), current_user: User = Depends(get_current_user)
|
|
):
|
|
"""Get statistics broken down by marketplace (Protected)."""
|
|
marketplace_stats = stats_service.get_marketplace_breakdown_stats(db=db)
|
|
|
|
return [
|
|
MarketplaceStatsResponse(
|
|
marketplace=stat["marketplace"],
|
|
total_products=stat["total_products"],
|
|
unique_vendors=stat["unique_vendors"],
|
|
unique_brands=stat["unique_brands"],
|
|
)
|
|
for stat in marketplace_stats
|
|
]
|