Spaces:
Sleeping
Sleeping
Update backend with high-quality catalog and fixes
Browse files- app/api/seed.py +19 -37
- app/api/seed_dummyjson.py +214 -0
- real_products_1000.json +0 -0
app/api/seed.py
CHANGED
|
@@ -5,6 +5,7 @@ import json
|
|
| 5 |
import random
|
| 6 |
import os
|
| 7 |
import hashlib
|
|
|
|
| 8 |
|
| 9 |
from app.db.base import get_db
|
| 10 |
from app.models.product import Product, ProductImage, Category
|
|
@@ -22,12 +23,12 @@ CATEGORY_MAP = {
|
|
| 22 |
"الأزياء": ["الملابس الرجالية", "الملابس النسائية"],
|
| 23 |
"الأحذية والحقائب": ["الأحذية", "الحقائب"],
|
| 24 |
"الأطفال والألعاب": ["الأطفال"],
|
| 25 |
-
"المنزل والمطبخ": ["المستلزمات المنزلية", "
|
| 26 |
-
"العطور والتجميل": ["العطور", "التجميل والعناية"],
|
| 27 |
-
"الأجهزة الإلكترونية": ["الهواتف والإلكترونيات", "الأجهزة ال
|
| 28 |
-
"الساعات والإكسسوارات": ["الساعات والاكسسوارات"],
|
| 29 |
-
"الرياضة واللياقة": ["الرياضة واللياقة"],
|
| 30 |
-
"ملحقات السيارات": ["ملحقات السيارات"],
|
| 31 |
}
|
| 32 |
|
| 33 |
# Emoji icons for frontend display
|
|
@@ -35,15 +36,17 @@ PARENT_ICONS = {
|
|
| 35 |
"الأزياء": "👗", "الأحذية والحقائب": "👟", "الأطفال والألعاب": "🧸",
|
| 36 |
"المنزل والمطبخ": "🏠", "العطور والتجميل": "✨", "الأجهزة الإلكترونية": "📱",
|
| 37 |
"الساعات والإكسسوارات": "⌚", "الرياضة واللياقة": "🏋️",
|
| 38 |
-
"ملحقات السيارات": "🚗",
|
| 39 |
}
|
| 40 |
SUB_ICONS = {
|
| 41 |
"الملابس الرجالية": "👔", "الملابس النسائية": "👗", "الأحذية": "👟",
|
| 42 |
"الحقائب": "👜", "الأطفال": "🧸", "المنزل والمطبخ": "🏠",
|
| 43 |
-
"المستلزمات المنزلية": "🧹", "ال
|
| 44 |
-
"ال
|
| 45 |
-
"ال
|
| 46 |
-
"ال
|
|
|
|
|
|
|
|
|
|
| 47 |
}
|
| 48 |
|
| 49 |
@router.api_route("", methods=["GET", "POST"], response_model=AuthResponse)
|
|
@@ -90,32 +93,11 @@ async def seed_database(clear: bool = False, db: Session = Depends(get_db)):
|
|
| 90 |
statusCode=200,
|
| 91 |
)
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
os.path.join(backend_root, "backend", "real_products_1000.json"),
|
| 99 |
-
"/app/real_products_1000.json",
|
| 100 |
-
"real_products_1000.json"
|
| 101 |
-
]
|
| 102 |
-
|
| 103 |
-
json_path = None
|
| 104 |
-
for p in possible_paths:
|
| 105 |
-
if os.path.exists(p):
|
| 106 |
-
json_path = p
|
| 107 |
-
break
|
| 108 |
-
|
| 109 |
-
if not json_path:
|
| 110 |
-
# Fallback to old names if 1000 not found
|
| 111 |
-
fallback_names = ["real_products_5000.json", "real_products_scraped.json"]
|
| 112 |
-
for name in fallback_names:
|
| 113 |
-
p = os.path.join(backend_root, name)
|
| 114 |
-
if os.path.exists(p):
|
| 115 |
-
json_path = p
|
| 116 |
-
break
|
| 117 |
-
|
| 118 |
-
if not json_path:
|
| 119 |
return AuthResponse(
|
| 120 |
isSuccess=False,
|
| 121 |
value={"message": f"Source file {json_path} not found."},
|
|
|
|
| 5 |
import random
|
| 6 |
import os
|
| 7 |
import hashlib
|
| 8 |
+
import requests
|
| 9 |
|
| 10 |
from app.db.base import get_db
|
| 11 |
from app.models.product import Product, ProductImage, Category
|
|
|
|
| 23 |
"الأزياء": ["الملابس الرجالية", "الملابس النسائية"],
|
| 24 |
"الأحذية والحقائب": ["الأحذية", "الحقائب"],
|
| 25 |
"الأطفال والألعاب": ["الأطفال"],
|
| 26 |
+
"المنزل والمطبخ": ["المنزل والمطبخ", "المستلزمات المنزلية", "مستلزمات المطبخ", "ديكور المنزل", "الأثاث", "الإضاءة"],
|
| 27 |
+
"العطور والتجميل": ["العطور", "التجميل والعناية", "الجمال", "العناية بالبشرة"],
|
| 28 |
+
"الأجهزة الإلكترونية": ["الهواتف والإلكترونيات", "الهواتف الذكية", "أجهزة الكمبيوتر"],
|
| 29 |
+
"الساعات والإكسسوارات": ["الساعات والاكسسوارات", "ساعات نسائية", "ساعات رجالية", "نظارات شمسية"],
|
| 30 |
+
"الرياضة واللياقة": ["الرياضة واللياقة", "إكسسوارات رياضية"],
|
| 31 |
+
"ملحقات السيارات": ["ملحقات السيارات", "إكسسوارات السيارات", "إكسسوارات الدراجات"],
|
| 32 |
}
|
| 33 |
|
| 34 |
# Emoji icons for frontend display
|
|
|
|
| 36 |
"الأزياء": "👗", "الأحذية والحقائب": "👟", "الأطفال والألعاب": "🧸",
|
| 37 |
"المنزل والمطبخ": "🏠", "العطور والتجميل": "✨", "الأجهزة الإلكترونية": "📱",
|
| 38 |
"الساعات والإكسسوارات": "⌚", "الرياضة واللياقة": "🏋️",
|
|
|
|
| 39 |
}
|
| 40 |
SUB_ICONS = {
|
| 41 |
"الملابس الرجالية": "👔", "الملابس النسائية": "👗", "الأحذية": "👟",
|
| 42 |
"الحقائب": "👜", "الأطفال": "🧸", "المنزل والمطبخ": "🏠",
|
| 43 |
+
"المستلزمات المنزلية": "🧹", "العطور": "🌸", "التجميل والعناية": "💄",
|
| 44 |
+
"الهواتف والإلكترونيات": "📱", "الساعات والاكسسوارات": "⌚",
|
| 45 |
+
"الرياضة واللياقة": "🏋️", "مستلزمات المطبخ": "🍳", "ديكور المنزل": "🪑",
|
| 46 |
+
"الأثاث": "🛋️", "الإضاءة": "💡", "الجمال": "💅", "العناية بالبشرة": "🧴",
|
| 47 |
+
"الهواتف الذكية": "📱", "أجهزة الكمبيوتر": "💻", "ساعات نسائية": "⌚",
|
| 48 |
+
"ساعات رجالية": "⌚", "نظارات شمسية": "🕶️", "إكسسوارات رياضية": "🏃",
|
| 49 |
+
"إكسسوارات السيارات": "🚗", "إكسسوارات الدراجات": "🏍️",
|
| 50 |
}
|
| 51 |
|
| 52 |
@router.api_route("", methods=["GET", "POST"], response_model=AuthResponse)
|
|
|
|
| 93 |
statusCode=200,
|
| 94 |
)
|
| 95 |
|
| 96 |
+
json_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "real_products_5000.json")
|
| 97 |
+
if not os.path.exists(json_path):
|
| 98 |
+
json_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "real_products_scraped.json")
|
| 99 |
+
|
| 100 |
+
if not os.path.exists(json_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
return AuthResponse(
|
| 102 |
isSuccess=False,
|
| 103 |
value={"message": f"Source file {json_path} not found."},
|
app/api/seed_dummyjson.py
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
DUMMYJSON_CATEGORIES = {
|
| 3 |
+
"smartphones": "الهواتف الذكية",
|
| 4 |
+
"laptops": "أجهزة الكمبيوتر",
|
| 5 |
+
"fragrances": "العطور",
|
| 6 |
+
"skincare": "العناية بالبشرة",
|
| 7 |
+
"groceries": "المقومات",
|
| 8 |
+
"home-decoration": "ديكور المنزل",
|
| 9 |
+
"furniture": "الأثاث",
|
| 10 |
+
"lighting": "الإضاءة",
|
| 11 |
+
"shoes": "الأحذية",
|
| 12 |
+
"mens-shirts": "الملابس الرجالية",
|
| 13 |
+
"womens-dresses": "الفساتين النسائية",
|
| 14 |
+
"womens-shoes": "الأحذية النسائية",
|
| 15 |
+
"womens-watches": "ساعات نسائية",
|
| 16 |
+
"mens-watches": "ساعات رجالية",
|
| 17 |
+
"sunglasses": "نظارات شمسية",
|
| 18 |
+
"automotive": "إكسسوارات السيارات",
|
| 19 |
+
"motorcycle": "إكسسوارات الدراجات",
|
| 20 |
+
"sports-accessories": "إكسسوارات رياضية",
|
| 21 |
+
"beauty": "الجمال",
|
| 22 |
+
"mobile-accessories": "إكسسوارات الهواتف",
|
| 23 |
+
"kitchen-accessories": "مستلزمات المطبخ",
|
| 24 |
+
"pet-supplies": "مستلزمات الحيوانات",
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
ARABIC_TRANSLATIONS = {
|
| 28 |
+
"iPhone": "آيفون", "Samsung": "سامسونج", "MacBook": "ماك بوك", "Air": "آير",
|
| 29 |
+
"Pro": "برو", "Max": "ماكس", "Ultra": "ألترا", "Plus": "بلس", "Premium": "بريميوم",
|
| 30 |
+
"Standard": "قياسي", "Classic": "كلاسيك", "New": "جديد", "Edition": "إصدار",
|
| 31 |
+
"2024": "2024", "2025": "2025", "Black": "أسود", "White": "أبيض", "Silver": "فضي",
|
| 32 |
+
"Gold": "ذهبي", "Blue": "أزرق", "Red": "أحمر", "Green": "أخضر", "Gray": "رمادي",
|
| 33 |
+
"Pink": "وردي", "Purple": "بنفسجي", "Leather": "جلد", "Wireless": "لاسلكي",
|
| 34 |
+
"Bluetooth": "بلوتوث", "USB": "يو إس بي", "Fast": "سريع", "Charging": "شحن",
|
| 35 |
+
"Camera": "كاميرا", "Screen": "شاشة", "Inch": "بوصة", "4K": "4 كيه",
|
| 36 |
+
"OLED": "أوليد", "LED": "ليد", "Smart": "ذكي", "Digital": "رقمي",
|
| 37 |
+
"Portable": "محمول", "Compact": "مدمج", "Waterproof": "مقاوم للماء",
|
| 38 |
+
"Case": "جراب", "Cover": "غطاء", "Bag": "حقيبة", "Stand": "حامل",
|
| 39 |
+
"Watch": "ساعة", "Earbuds": "إيربودز", "Headphones": "سماعات", "Speaker": "مكبر صوت",
|
| 40 |
+
"Keyboard": "لوحة مفاتيح", "Mouse": "فأرة", "Tablet": "جهاز لوحي",
|
| 41 |
+
"Printer": "طابعة", "Fan": "مروحة", "Air": "هواء", "Purifier": "منقي",
|
| 42 |
+
"Vacuum": "مكنسة", "Cleaner": "منظف", "Iron": "مكواة", "Blender": "خلاط",
|
| 43 |
+
"Coffee": "قهوة", "Tea": "شاي", "Perfume": "عطر", "Cream": "كريمة",
|
| 44 |
+
"Sunscreen": "واقي شمس", "Moisturizer": "مرطب", "Foundation": "فاونديشن",
|
| 45 |
+
"Lipstick": "أحمر شفاه", "Hair": "شعر", "Body": "جسم", "Face": "وجه",
|
| 46 |
+
"Sofa": "أريكة", "Chair": "كرسي", "Table": "طاولة", "Bed": "سرير",
|
| 47 |
+
"Lamp": "مصباح", "Light": "ضوء", "Clock": "ساعة حائط", "Mirror": "مرآة",
|
| 48 |
+
"Sunglasses": "نظارات شمسية", "Tire": "إطار", "Oil": "زيت",
|
| 49 |
+
"Drill": "مثقاب", "Hammer": "مطرقة", "Tool": "أداة", "Kit": "طقم",
|
| 50 |
+
"Ball": "كرة", "Dumbbell": "دمبل", "Yoga": "يوجا", "Fitness": "لياقة",
|
| 51 |
+
"Sport": "رياضة", "Outdoor": "خارجي", "Travel": "سفر", "Accessories": "إكسسوارات",
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
def translate_to_arabic(text: str) -> str:
|
| 55 |
+
result = text
|
| 56 |
+
for eng, ar in ARABIC_TRANSLATIONS.items():
|
| 57 |
+
result = result.replace(eng, ar)
|
| 58 |
+
return result if result != text else f"{text} - منتج مميز"
|
| 59 |
+
|
| 60 |
+
@router.get("/dummyjson", response_model=AuthResponse)
|
| 61 |
+
async def seed_from_dummyjson(clear: bool = False, db: Session = Depends(get_db)):
|
| 62 |
+
"""Fetch products from DummyJSON API with working images."""
|
| 63 |
+
if clear:
|
| 64 |
+
db.execute(text("DELETE FROM product_images"))
|
| 65 |
+
db.execute(text("DELETE FROM products"))
|
| 66 |
+
db.execute(text("DELETE FROM categories"))
|
| 67 |
+
db.execute(text("DELETE FROM coupons"))
|
| 68 |
+
try:
|
| 69 |
+
db.execute(text("ALTER TABLE products ADD COLUMN specs JSON"))
|
| 70 |
+
except Exception:
|
| 71 |
+
pass
|
| 72 |
+
db.commit()
|
| 73 |
+
|
| 74 |
+
admin_exists = db.execute(text("SELECT id FROM users WHERE email = 'admin@vortex.com'")).fetchone()
|
| 75 |
+
if not admin_exists:
|
| 76 |
+
admin_user = User(
|
| 77 |
+
name="Admin", email="admin@vortex.com", password_hash=hash_password("admin123"),
|
| 78 |
+
role=UserRole.ADMIN, auth_provider=AuthProvider.LOCAL,
|
| 79 |
+
)
|
| 80 |
+
db.add(admin_user)
|
| 81 |
+
db.commit()
|
| 82 |
+
|
| 83 |
+
dummy_parent_cats = {
|
| 84 |
+
"الأجهزة الإلكترونية": "📱", "العطور والتجميل": "✨", "المنزل والمطبخ": "🏠",
|
| 85 |
+
"الأزياء والعبايات": "👕", "الإكسسوارات": "⌚", "ملحقات السيارات": "🚗",
|
| 86 |
+
"الرياضة واللياقة": "🏋️",
|
| 87 |
+
}
|
| 88 |
+
dummy_sub_cats = {
|
| 89 |
+
"الهواتف الذكية": ("الأج��زة الإلكترونية", "smartphones"),
|
| 90 |
+
"أجهزة الكمبيوتر": ("الأجهزة الإلكترونية", "laptops"),
|
| 91 |
+
"العطور": ("العطور والتجميل", "fragrances"),
|
| 92 |
+
"التجميل والعناية": ("العطور والتجميل", "skincare"),
|
| 93 |
+
"المستلزمات المنزلية": ("المنزل والمطبخ", "groceries"),
|
| 94 |
+
"ديكور المنزل": ("المنزل والمطبخ", "home-decoration"),
|
| 95 |
+
"الأثاث": ("المنزل والمطبخ", "furniture"),
|
| 96 |
+
"الإضاءة": ("المنزل والمطبخ", "lighting"),
|
| 97 |
+
"الأحذية": ("الأزياء والعبايات", "shoes"),
|
| 98 |
+
"الملابس الرجالية": ("الأزياء والعبايات", "mens-shirts"),
|
| 99 |
+
"الفساتين النسائية": ("الأزياء والعبايات", "womens-dresses"),
|
| 100 |
+
"الأحذية النسائية": ("الأزياء والعبايات", "womens-shoes"),
|
| 101 |
+
"ساعات نسائية": ("الإكسسوارات", "womens-watches"),
|
| 102 |
+
"ساعات رجالية": ("الإكسسوارات", "mens-watches"),
|
| 103 |
+
"نظارات شمسية": ("الإكسسوارات", "sunglasses"),
|
| 104 |
+
"إكسسوارات السيارات": ("ملحقات السيارات", "automotive"),
|
| 105 |
+
"إكسسوارات الدراجات": ("ملحقات السيارات", "motorcycle"),
|
| 106 |
+
"إكسسوارات رياضية": ("الرياضة واللياقة", "sports-accessories"),
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
parent_cat_models = {}
|
| 110 |
+
for name, icon in dummy_parent_cats.items():
|
| 111 |
+
parent = db.query(Category).filter(Category.name_ar == name).first()
|
| 112 |
+
if not parent:
|
| 113 |
+
parent = Category(name_ar=name, name_en=name, icon=icon)
|
| 114 |
+
db.add(parent)
|
| 115 |
+
db.commit()
|
| 116 |
+
db.refresh(parent)
|
| 117 |
+
parent_cat_models[name] = parent
|
| 118 |
+
|
| 119 |
+
sub_cat_models = {}
|
| 120 |
+
for sub_name, (parent_name, dummy_cat) in dummy_sub_cats.items():
|
| 121 |
+
sub = db.query(Category).filter(Category.name_ar == sub_name).first()
|
| 122 |
+
if not sub:
|
| 123 |
+
sub = Category(name_ar=sub_name, name_en=sub_name, parent_id=parent_cat_models[parent_name].id)
|
| 124 |
+
db.add(sub)
|
| 125 |
+
db.commit()
|
| 126 |
+
db.refresh(sub)
|
| 127 |
+
sub_cat_models[dummy_cat] = {"model": sub, "parent": parent_name}
|
| 128 |
+
|
| 129 |
+
print("[*] Fetching products from DummyJSON...")
|
| 130 |
+
all_products = []
|
| 131 |
+
skip = 0
|
| 132 |
+
limit = 100
|
| 133 |
+
|
| 134 |
+
while True:
|
| 135 |
+
try:
|
| 136 |
+
resp = requests.get(f"https://dummyjson.com/products?limit={limit}&skip={skip}&select=title,description,price,discountPercentage,rating,category,thumbnail,images")
|
| 137 |
+
if not resp.ok:
|
| 138 |
+
break
|
| 139 |
+
data = resp.json()
|
| 140 |
+
products = data.get("products", [])
|
| 141 |
+
if not products:
|
| 142 |
+
break
|
| 143 |
+
all_products.extend(products)
|
| 144 |
+
print(f" Fetched {len(all_products)} / {data.get('total', '?')}")
|
| 145 |
+
skip += limit
|
| 146 |
+
if skip >= data.get("total", 0):
|
| 147 |
+
break
|
| 148 |
+
except Exception as e:
|
| 149 |
+
print(f"Error: {e}")
|
| 150 |
+
break
|
| 151 |
+
|
| 152 |
+
inserted = 0
|
| 153 |
+
for p in all_products:
|
| 154 |
+
dummy_cat = p.get("category", "")
|
| 155 |
+
if dummy_cat not in sub_cat_models:
|
| 156 |
+
continue
|
| 157 |
+
|
| 158 |
+
cat_info = sub_cat_models[dummy_cat]
|
| 159 |
+
price = p.get("price", 0)
|
| 160 |
+
saudi_price = price * 3.75
|
| 161 |
+
compare_price = saudi_price * 1.4
|
| 162 |
+
|
| 163 |
+
images = p.get("images", [])
|
| 164 |
+
if not images and p.get("thumbnail"):
|
| 165 |
+
images = [p["thumbnail"]]
|
| 166 |
+
|
| 167 |
+
prod = Product(
|
| 168 |
+
name_ar=translate_to_arabic(p.get("title", "")),
|
| 169 |
+
name_en=p.get("title", ""),
|
| 170 |
+
description_ar=translate_to_arabic(p.get("description", "")),
|
| 171 |
+
description_en=p.get("description", ""),
|
| 172 |
+
price=round(saudi_price, 2),
|
| 173 |
+
compare_price=round(compare_price, 2),
|
| 174 |
+
stock=random.randint(10, 100),
|
| 175 |
+
category_id=cat_info["model"].id,
|
| 176 |
+
rating=round(p.get("rating", 4.0), 1),
|
| 177 |
+
rating_count=random.randint(10, 500),
|
| 178 |
+
is_featured=random.choice([True, False]),
|
| 179 |
+
is_active=True,
|
| 180 |
+
specs={}
|
| 181 |
+
)
|
| 182 |
+
db.add(prod)
|
| 183 |
+
db.flush()
|
| 184 |
+
|
| 185 |
+
for i, img_url in enumerate(images):
|
| 186 |
+
db.add(ProductImage(
|
| 187 |
+
product_id=prod.id,
|
| 188 |
+
image_url=img_url,
|
| 189 |
+
alt_text=prod.name_ar,
|
| 190 |
+
sort_order=i
|
| 191 |
+
))
|
| 192 |
+
|
| 193 |
+
inserted += 1
|
| 194 |
+
|
| 195 |
+
DEMO_COUPONS = [
|
| 196 |
+
{"code": "WELCOME10", "discount_percent": 10.0, "is_active": True},
|
| 197 |
+
{"code": "VORTEX20", "discount_percent": 20.0, "is_active": True},
|
| 198 |
+
{"code": "SUMMER50", "discount_percent": 50.0, "is_active": False},
|
| 199 |
+
]
|
| 200 |
+
for coupon_data in DEMO_COUPONS:
|
| 201 |
+
db.add(Coupon(**coupon_data))
|
| 202 |
+
|
| 203 |
+
db.commit()
|
| 204 |
+
|
| 205 |
+
return AuthResponse(
|
| 206 |
+
isSuccess=True,
|
| 207 |
+
value={
|
| 208 |
+
"message": "تم تهيئة المنتجات من DummyJSON بنجاح",
|
| 209 |
+
"categories_count": db.query(Category).count(),
|
| 210 |
+
"total_products": inserted,
|
| 211 |
+
"coupons_count": len(DEMO_COUPONS),
|
| 212 |
+
},
|
| 213 |
+
statusCode=201,
|
| 214 |
+
)
|
real_products_1000.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|