feat: add proper Pydantic response_model to all stats endpoints
- Create comprehensive stats schemas in models/schema/stats.py: - ImportStatsResponse, UserStatsResponse, ProductStatsResponse - PlatformStatsResponse, AdminDashboardResponse - VendorDashboardStatsResponse with nested models - VendorAnalyticsResponse, CodeQualityDashboardStatsResponse - Move DashboardStatsResponse from code_quality.py to schema file - Fix get_vendor_statistics() to return pending_vendors field - Fix get_vendor_stats() to return flat structure matching schema - Add response_model to all stats endpoints: - GET /admin/dashboard -> AdminDashboardResponse - GET /admin/dashboard/stats/platform -> PlatformStatsResponse - GET /admin/marketplace-import-jobs/stats -> ImportStatsResponse - GET /vendor/dashboard/stats -> VendorDashboardStatsResponse - GET /vendor/analytics -> VendorAnalyticsResponse - Enhance API-001 architecture rule with detailed guidance - Add SVC-007 rule for service/schema compatibility 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
58
app/api/v1/vendor/dashboard.py
vendored
58
app/api/v1/vendor/dashboard.py
vendored
@@ -17,12 +17,20 @@ from app.exceptions import VendorNotActiveException
|
||||
from app.services.stats_service import stats_service
|
||||
from app.services.vendor_service import vendor_service
|
||||
from models.database.user import User
|
||||
from models.schema.stats import (
|
||||
VendorCustomerStats,
|
||||
VendorDashboardStatsResponse,
|
||||
VendorInfo,
|
||||
VendorOrderStats,
|
||||
VendorProductStats,
|
||||
VendorRevenueStats,
|
||||
)
|
||||
|
||||
router = APIRouter(prefix="/dashboard")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@router.get("/stats")
|
||||
@router.get("/stats", response_model=VendorDashboardStatsResponse)
|
||||
def get_vendor_dashboard_stats(
|
||||
request: Request,
|
||||
current_user: User = Depends(get_current_vendor_api),
|
||||
@@ -51,27 +59,27 @@ def get_vendor_dashboard_stats(
|
||||
# Get vendor-scoped statistics
|
||||
stats_data = stats_service.get_vendor_stats(db=db, vendor_id=vendor_id)
|
||||
|
||||
return {
|
||||
"vendor": {
|
||||
"id": vendor.id,
|
||||
"name": vendor.name,
|
||||
"vendor_code": vendor.vendor_code,
|
||||
},
|
||||
"products": {
|
||||
"total": stats_data.get("total_products", 0),
|
||||
"active": stats_data.get("active_products", 0),
|
||||
},
|
||||
"orders": {
|
||||
"total": stats_data.get("total_orders", 0),
|
||||
"pending": stats_data.get("pending_orders", 0),
|
||||
"completed": stats_data.get("completed_orders", 0),
|
||||
},
|
||||
"customers": {
|
||||
"total": stats_data.get("total_customers", 0),
|
||||
"active": stats_data.get("active_customers", 0),
|
||||
},
|
||||
"revenue": {
|
||||
"total": stats_data.get("total_revenue", 0),
|
||||
"this_month": stats_data.get("revenue_this_month", 0),
|
||||
},
|
||||
}
|
||||
return VendorDashboardStatsResponse(
|
||||
vendor=VendorInfo(
|
||||
id=vendor.id,
|
||||
name=vendor.name,
|
||||
vendor_code=vendor.vendor_code,
|
||||
),
|
||||
products=VendorProductStats(
|
||||
total=stats_data.get("total_products", 0),
|
||||
active=stats_data.get("active_products", 0),
|
||||
),
|
||||
orders=VendorOrderStats(
|
||||
total=stats_data.get("total_orders", 0),
|
||||
pending=stats_data.get("pending_orders", 0),
|
||||
completed=stats_data.get("completed_orders", 0),
|
||||
),
|
||||
customers=VendorCustomerStats(
|
||||
total=stats_data.get("total_customers", 0),
|
||||
active=stats_data.get("active_customers", 0),
|
||||
),
|
||||
revenue=VendorRevenueStats(
|
||||
total=stats_data.get("total_revenue", 0),
|
||||
this_month=stats_data.get("revenue_this_month", 0),
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user