Spaces:
Sleeping
Sleeping
Update routers/electronics_router.py
Browse files- routers/electronics_router.py +25 -33
routers/electronics_router.py
CHANGED
@@ -6,14 +6,6 @@ import random
|
|
6 |
|
7 |
router = APIRouter(prefix="/api/electronics", tags=["electronics"])
|
8 |
|
9 |
-
class ElectronicProduct(BaseModel):
|
10 |
-
id: int
|
11 |
-
name: str
|
12 |
-
category: str
|
13 |
-
price: float
|
14 |
-
specs: dict
|
15 |
-
stock: int
|
16 |
-
rating: float
|
17 |
|
18 |
@router.get("/products")
|
19 |
async def get_products():
|
@@ -21,32 +13,32 @@ async def get_products():
|
|
21 |
categories = ["Smartphones", "Laptops", "Tablets", "Smartwatches"]
|
22 |
products = []
|
23 |
|
24 |
-
for i in range(20):
|
25 |
-
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
|
52 |
return {"products": products}
|
|
|
6 |
|
7 |
router = APIRouter(prefix="/api/electronics", tags=["electronics"])
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
@router.get("/products")
|
11 |
async def get_products():
|
|
|
13 |
categories = ["Smartphones", "Laptops", "Tablets", "Smartwatches"]
|
14 |
products = []
|
15 |
|
16 |
+
# for i in range(20):
|
17 |
+
# category = random.choice(categories)
|
18 |
|
19 |
+
# specs = {
|
20 |
+
# "Smartphones": {
|
21 |
+
# "screen": f"{random.choice([5.5, 6.1, 6.7])} inches",
|
22 |
+
# "storage": f"{random.choice([64, 128, 256, 512])}GB",
|
23 |
+
# "ram": f"{random.choice([4, 6, 8, 12])}GB",
|
24 |
+
# "camera": f"{random.choice([12, 48, 64, 108])}MP"
|
25 |
+
# },
|
26 |
+
# "Laptops": {
|
27 |
+
# "screen": f"{random.choice([13, 14, 15.6, 16])} inches",
|
28 |
+
# "storage": f"{random.choice([256, 512, 1024])}GB SSD",
|
29 |
+
# "ram": f"{random.choice([8, 16, 32])}GB",
|
30 |
+
# "processor": f"Core i{random.choice([5, 7, 9])}"
|
31 |
+
# }
|
32 |
+
# }.get(category, {"specs": "Basic specifications"})
|
33 |
|
34 |
+
# products.append({
|
35 |
+
# "id": i + 1,
|
36 |
+
# "name": f"{category} Pro {random.randint(1, 100)}",
|
37 |
+
# "category": category,
|
38 |
+
# "price": round(random.uniform(299.99, 2999.99), 2),
|
39 |
+
# "specs": specs,
|
40 |
+
# "stock": random.randint(0, 100),
|
41 |
+
# "rating": round(random.uniform(3.5, 5.0), 1)
|
42 |
+
# })
|
43 |
|
44 |
return {"products": products}
|