Database & Migrations: - Add application_logs table migration for hybrid cloud logging - Add companies table migration and restructure vendor relationships Logging System: - Implement hybrid logging system (database + file) - Add log_service for centralized log management - Create admin logs page with filtering and viewing capabilities - Add init_log_settings.py script for log configuration - Enhance core logging with database integration Marketplace Integration: - Add marketplace admin page with product management - Create marketplace vendor page with product listings - Implement marketplace.js for both admin and vendor interfaces - Add marketplace integration documentation Admin Enhancements: - Add imports management page and functionality - Create settings page for admin configuration - Add vendor themes management page - Enhance vendor detail and edit pages - Improve code quality dashboard and violation details - Add logs viewing and management - Update icons guide and shared icon system Architecture & Documentation: - Document frontend structure and component architecture - Document models structure and relationships - Add vendor-in-token architecture documentation - Add vendor RBAC (role-based access control) documentation - Document marketplace integration patterns - Update architecture patterns documentation Infrastructure: - Add platform static files structure (css, img, js) - Move architecture_scan.py to proper models location - Update model imports and registrations - Enhance exception handling - Update dependency injection patterns UI/UX: - Improve vendor edit interface - Update admin user interface - Enhance page templates documentation - Add vendor marketplace interface
83 lines
2.5 KiB
Python
83 lines
2.5 KiB
Python
# app/api/v1/vendor/dashboard.py
|
|
"""
|
|
Vendor dashboard and statistics endpoints.
|
|
"""
|
|
|
|
import logging
|
|
|
|
from fastapi import APIRouter, Depends, Request
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.api.deps import get_current_vendor_api
|
|
from app.core.database import get_db
|
|
from app.services.stats_service import stats_service
|
|
from models.database.user import User
|
|
|
|
router = APIRouter(prefix="/dashboard")
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@router.get("/stats")
|
|
def get_vendor_dashboard_stats(
|
|
request: Request,
|
|
current_user: User = Depends(get_current_vendor_api),
|
|
db: Session = Depends(get_db),
|
|
):
|
|
"""
|
|
Get vendor-specific dashboard statistics.
|
|
|
|
Returns statistics for the current vendor only:
|
|
- Total products in catalog
|
|
- Total orders
|
|
- Total customers
|
|
- Revenue metrics
|
|
|
|
Vendor is determined from the JWT token (vendor_id claim).
|
|
Requires Authorization header (API endpoint).
|
|
"""
|
|
from fastapi import HTTPException
|
|
|
|
# Get vendor ID from token (set by get_current_vendor_api)
|
|
if not hasattr(current_user, "token_vendor_id"):
|
|
raise HTTPException(
|
|
status_code=400,
|
|
detail="Token missing vendor information. Please login again.",
|
|
)
|
|
|
|
vendor_id = current_user.token_vendor_id
|
|
|
|
# Get vendor object to include in response
|
|
from models.database.vendor import Vendor
|
|
|
|
vendor = db.query(Vendor).filter(Vendor.id == vendor_id).first()
|
|
if not vendor or not vendor.is_active:
|
|
raise HTTPException(status_code=404, detail="Vendor not found or inactive")
|
|
|
|
# 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),
|
|
},
|
|
}
|