diff --git a/models/schema/customer.py b/models/schema/customer.py index 11bf7aa9..3be4c89a 100644 --- a/models/schema/customer.py +++ b/models/schema/customer.py @@ -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 # ============================================================================ diff --git a/models/schema/order.py b/models/schema/order.py index 4c290778..6d34e9ef 100644 --- a/models/schema/order.py +++ b/models/schema/order.py @@ -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 diff --git a/models/schema/stats.py b/models/schema/stats.py index 95ac9a26..0bdf9b65 100644 --- a/models/schema/stats.py +++ b/models/schema/stats.py @@ -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") \ No newline at end of file diff --git a/tests/unit/services/test_admin_service.py b/tests/unit/services/test_admin_service.py index b03bd377..01b9374a 100644 --- a/tests/unit/services/test_admin_service.py +++ b/tests/unit/services/test_admin_service.py @@ -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