Upload app/api/admin.py
Browse files- app/api/admin.py +48 -0
app/api/admin.py
CHANGED
|
@@ -107,3 +107,51 @@ def get_payment_records(
|
|
| 107 |
"value": {"payments": results},
|
| 108 |
"statusCode": 200
|
| 109 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
"value": {"payments": results},
|
| 108 |
"statusCode": 200
|
| 109 |
}
|
| 110 |
+
|
| 111 |
+
@router.get("/customers")
|
| 112 |
+
def get_all_customers(
|
| 113 |
+
current_user_id: int = Depends(get_current_user),
|
| 114 |
+
db: Session = Depends(get_db)
|
| 115 |
+
):
|
| 116 |
+
"""List all registered customers."""
|
| 117 |
+
check_admin(current_user_id, db)
|
| 118 |
+
customers = db.query(User).filter(User.role == UserRole.CUSTOMER).order_by(User.created_at.desc()).all()
|
| 119 |
+
|
| 120 |
+
results = [{
|
| 121 |
+
"id": c.id,
|
| 122 |
+
"name": c.name,
|
| 123 |
+
"email": c.email,
|
| 124 |
+
"phone": c.phone,
|
| 125 |
+
"created_at": c.created_at.isoformat(),
|
| 126 |
+
"auth_provider": c.auth_provider
|
| 127 |
+
} for c in customers]
|
| 128 |
+
|
| 129 |
+
return {
|
| 130 |
+
"isSuccess": True,
|
| 131 |
+
"value": {"customers": results},
|
| 132 |
+
"statusCode": 200
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
@router.get("/orders")
|
| 136 |
+
def get_all_orders(
|
| 137 |
+
current_user_id: int = Depends(get_current_user),
|
| 138 |
+
db: Session = Depends(get_db)
|
| 139 |
+
):
|
| 140 |
+
"""List all orders in the system."""
|
| 141 |
+
check_admin(current_user_id, db)
|
| 142 |
+
orders = db.query(Order).order_by(Order.created_at.desc()).all()
|
| 143 |
+
|
| 144 |
+
results = [{
|
| 145 |
+
"id": o.id,
|
| 146 |
+
"customer_name": o.user.name if o.user else "Guest",
|
| 147 |
+
"customer_email": o.user.email if o.user else o.guest_email,
|
| 148 |
+
"total_amount": float(o.total_price),
|
| 149 |
+
"status": o.status.value,
|
| 150 |
+
"created_at": o.created_at.isoformat()
|
| 151 |
+
} for o in orders]
|
| 152 |
+
|
| 153 |
+
return {
|
| 154 |
+
"isSuccess": True,
|
| 155 |
+
"value": {"orders": results},
|
| 156 |
+
"statusCode": 200
|
| 157 |
+
}
|