Spaces:
Sleeping
Sleeping
Update backend with high-quality catalog and fixes
Browse files- app/api/admin.py +6 -1
- app/api/products.py +16 -5
app/api/admin.py
CHANGED
|
@@ -106,7 +106,12 @@ def get_dashboard_stats(
|
|
| 106 |
|
| 107 |
low_stock_items = db.query(Product).filter(
|
| 108 |
Product.stock <= 10,
|
| 109 |
-
Product.is_active == True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
).limit(5).all()
|
| 111 |
|
| 112 |
low_stock_data = [{
|
|
|
|
| 106 |
|
| 107 |
low_stock_items = db.query(Product).filter(
|
| 108 |
Product.stock <= 10,
|
| 109 |
+
Product.is_active == True,
|
| 110 |
+
Product.deleted_at == None
|
| 111 |
+
).order_by(
|
| 112 |
+
func.abs(Product.id > 3708).desc(), # 1 if > 3708, 0 otherwise (Sort 1s first)
|
| 113 |
+
case((Product.id > 3708, Product.id), else_=None).desc(),
|
| 114 |
+
Product.id.asc()
|
| 115 |
).limit(5).all()
|
| 116 |
|
| 117 |
low_stock_data = [{
|
app/api/products.py
CHANGED
|
@@ -116,11 +116,22 @@ async def list_products(
|
|
| 116 |
total = query.count()
|
| 117 |
|
| 118 |
# Sort
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
# Pagination
|
| 126 |
offset = (page - 1) * page_size
|
|
|
|
| 116 |
total = query.count()
|
| 117 |
|
| 118 |
# Sort
|
| 119 |
+
from sqlalchemy import case
|
| 120 |
+
|
| 121 |
+
# Custom Hybrid Sorting Logic:
|
| 122 |
+
# 1. New Products (ID > 3708) first, sorted by ID DESC
|
| 123 |
+
# 2. Original Catalog (ID <= 3708) next, sorted by ID ASC
|
| 124 |
+
query = query.order_by(
|
| 125 |
+
case(
|
| 126 |
+
(Product.id > 3708, 0),
|
| 127 |
+
else_=1
|
| 128 |
+
),
|
| 129 |
+
case(
|
| 130 |
+
(Product.id > 3708, Product.id),
|
| 131 |
+
else_=None
|
| 132 |
+
).desc(),
|
| 133 |
+
Product.id.asc()
|
| 134 |
+
)
|
| 135 |
|
| 136 |
# Pagination
|
| 137 |
offset = (page - 1) * page_size
|