Stats management revamping
This commit is contained in:
@@ -163,23 +163,6 @@ class CustomerAddressResponse(BaseModel):
|
||||
"from_attributes": True
|
||||
}
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Customer Statistics
|
||||
# ============================================================================
|
||||
|
||||
class CustomerStatsResponse(BaseModel):
|
||||
"""Schema for customer statistics."""
|
||||
|
||||
customer_id: int
|
||||
total_orders: int
|
||||
total_spent: Decimal
|
||||
average_order_value: Decimal
|
||||
last_order_date: Optional[datetime]
|
||||
first_order_date: Optional[datetime]
|
||||
lifetime_value: Decimal
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Customer Preferences
|
||||
# ============================================================================
|
||||
|
||||
@@ -152,19 +152,3 @@ class OrderListResponse(BaseModel):
|
||||
total: int
|
||||
skip: int
|
||||
limit: int
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Order Statistics
|
||||
# ============================================================================
|
||||
|
||||
class OrderStatsResponse(BaseModel):
|
||||
"""Schema for order statistics."""
|
||||
total_orders: int
|
||||
pending_orders: int
|
||||
processing_orders: int
|
||||
shipped_orders: int
|
||||
delivered_orders: int
|
||||
cancelled_orders: int
|
||||
total_revenue: Decimal
|
||||
average_order_value: Decimal
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import re
|
||||
from decimal import Decimal
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
@@ -20,3 +21,45 @@ class MarketplaceStatsResponse(BaseModel):
|
||||
total_products: int
|
||||
unique_vendors: int
|
||||
unique_brands: int
|
||||
|
||||
# ============================================================================
|
||||
# Customer Statistics
|
||||
# ============================================================================
|
||||
|
||||
class CustomerStatsResponse(BaseModel):
|
||||
"""Schema for customer statistics."""
|
||||
|
||||
customer_id: int
|
||||
total_orders: int
|
||||
total_spent: Decimal
|
||||
average_order_value: Decimal
|
||||
last_order_date: Optional[datetime]
|
||||
first_order_date: Optional[datetime]
|
||||
lifetime_value: Decimal
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Order Statistics
|
||||
# ============================================================================
|
||||
|
||||
class OrderStatsResponse(BaseModel):
|
||||
"""Schema for order statistics."""
|
||||
total_orders: int
|
||||
pending_orders: int
|
||||
processing_orders: int
|
||||
shipped_orders: int
|
||||
delivered_orders: int
|
||||
cancelled_orders: int
|
||||
total_revenue: Decimal
|
||||
average_order_value: Decimal
|
||||
|
||||
# ============================================================================
|
||||
# Vendor Statistics
|
||||
# ============================================================================
|
||||
|
||||
class VendorStatsResponse(BaseModel):
|
||||
"""Vendor statistics response schema."""
|
||||
total: int = Field(..., description="Total number of vendors")
|
||||
verified: int = Field(..., description="Number of verified vendors")
|
||||
pending: int = Field(..., description="Number of pending verification vendors")
|
||||
inactive: int = Field(..., description="Number of inactive vendors")
|
||||
@@ -10,6 +10,7 @@ from app.exceptions import (
|
||||
AdminOperationException,
|
||||
)
|
||||
from app.services.admin_service import AdminService
|
||||
from app.services.stats_service import stats_service
|
||||
from models.database.marketplace_import_job import MarketplaceImportJob
|
||||
from models.database.vendor import Vendor
|
||||
|
||||
@@ -227,7 +228,7 @@ class TestAdminService:
|
||||
# Statistics Tests
|
||||
def test_get_user_statistics(self, db, test_user, test_admin):
|
||||
"""Test getting user statistics"""
|
||||
stats = self.service.get_user_statistics(db)
|
||||
stats = get_user_statistics(db)
|
||||
|
||||
assert "total_users" in stats
|
||||
assert "active_users" in stats
|
||||
@@ -244,7 +245,7 @@ class TestAdminService:
|
||||
|
||||
def test_get_vendor_statistics(self, db, test_vendor):
|
||||
"""Test getting vendor statistics"""
|
||||
stats = self.service.get_vendor_statistics(db)
|
||||
stats = stats_service.get_vendor_statistics(db)
|
||||
|
||||
assert "total_vendors" in stats
|
||||
assert "active_vendors" in stats
|
||||
@@ -291,7 +292,7 @@ class TestAdminService:
|
||||
|
||||
def test_user_statistics_empty_database(self, empty_db):
|
||||
"""Test user statistics when no users exist"""
|
||||
stats = self.service.get_user_statistics(empty_db)
|
||||
stats = stats_service.get_user_statistics(empty_db)
|
||||
|
||||
assert stats["total_users"] == 0
|
||||
assert stats["active_users"] == 0
|
||||
@@ -300,7 +301,7 @@ class TestAdminService:
|
||||
|
||||
def test_vendor_statistics_empty_database(self, empty_db):
|
||||
"""Test vendor statistics when no vendors exist"""
|
||||
stats = self.service.get_vendor_statistics(empty_db)
|
||||
stats = stats_service.get_vendor_statistics(empty_db)
|
||||
|
||||
assert stats["total_vendors"] == 0
|
||||
assert stats["active_vendors"] == 0
|
||||
|
||||
Reference in New Issue
Block a user