68 lines
2.4 KiB
Python
68 lines
2.4 KiB
Python
from fastapi import APIRouter, Depends, Query, HTTPException
|
|
from typing import Dict, Any, List
|
|
from app.core.config.Config import settings
|
|
|
|
router = APIRouter(
|
|
prefix="/api/v1/shipping",
|
|
tags=["Shiprocket Logistics"]
|
|
)
|
|
|
|
@router.get("/status")
|
|
def get_shipping_status():
|
|
"""Verify Shiprocket logistics configuration status."""
|
|
return {
|
|
"enabled": settings.SHIPROCKET_ENABLED,
|
|
"mode": settings.SHIPROCKET_MODE,
|
|
"pickup_location": settings.SHIPROCKET_PICKUP_LOCATION,
|
|
"pickup_pincode": settings.SHIPROCKET_PICKUP_PIN,
|
|
"notice": "Safe sandbox mode active. Live API dispatch disabled per user setting."
|
|
}
|
|
|
|
@router.get("/dashboard")
|
|
def get_shipping_dashboard():
|
|
"""Returns shipping wallet balance, shipment pipeline counts, and courier SLAs."""
|
|
return {
|
|
"status": "success",
|
|
"enabled": settings.SHIPROCKET_ENABLED,
|
|
"wallet": {
|
|
"balance": 2450.00,
|
|
"currency": "INR",
|
|
"low_balance": False
|
|
},
|
|
"shipment_counts": {
|
|
"ready_to_ship": 4,
|
|
"in_transit": 12,
|
|
"out_for_delivery": 3,
|
|
"delivered": 142,
|
|
"rto_returned": 2
|
|
},
|
|
"courier_performance": [
|
|
{"courier": "BlueDart Surface", "sla_days": "2-3", "on_time_pct": 98.4, "active_shipments": 6},
|
|
{"courier": "Delhivery Express", "sla_days": "1-2", "on_time_pct": 96.1, "active_shipments": 5},
|
|
{"courier": "Ekart Logistics", "sla_days": "2-4", "on_time_pct": 94.8, "active_shipments": 3},
|
|
{"courier": "DTDC Air", "sla_days": "1-2", "on_time_pct": 95.0, "active_shipments": 1}
|
|
]
|
|
}
|
|
|
|
@router.get("/rates")
|
|
def calculate_shipping_rates(
|
|
delivery_pincode: str = Query(..., regex=r"^\d{6}$"),
|
|
weight_kg: float = Query(0.5, ge=0.1, le=50.0)
|
|
):
|
|
"""Estimate shipping rates and delivery timeframe."""
|
|
return {
|
|
"status": "success",
|
|
"delivery_pincode": delivery_pincode,
|
|
"standard_delivery": {
|
|
"courier": "BlueDart Express",
|
|
"rate": 70.00 if weight_kg <= 1.0 else 120.00,
|
|
"estimated_days": "2 - 3 Days",
|
|
"cod_available": True
|
|
},
|
|
"express_delivery": {
|
|
"courier": "Delhivery Priority",
|
|
"rate": 140.00 if weight_kg <= 1.0 else 220.00,
|
|
"estimated_days": "1 - 2 Days",
|
|
"cod_available": True
|
|
}
|
|
}
|