File size: 1,597 Bytes
81ef07f
 
 
 
 
 
 
 
 
925f82c
81ef07f
 
 
 
 
8e2fea8
 
81ef07f
8e2fea8
 
 
 
 
 
 
 
 
 
 
 
 
 
81ef07f
8e2fea8
 
 
 
 
 
 
 
 
81ef07f
925f82c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# routers/electronics_router.py
from fastapi import APIRouter
from typing import List
from pydantic import BaseModel
import random

router = APIRouter(prefix="/api/electronics", tags=["electronics"])


@router.get("/products")
async def get_products():
    # Sample data generator
    categories = ["Smartphones", "Laptops", "Tablets", "Smartwatches"]
    products = []
    
    # for i in range(20):
    #     category = random.choice(categories)
        
    #     specs = {
    #         "Smartphones": {
    #             "screen": f"{random.choice([5.5, 6.1, 6.7])} inches",
    #             "storage": f"{random.choice([64, 128, 256, 512])}GB",
    #             "ram": f"{random.choice([4, 6, 8, 12])}GB",
    #             "camera": f"{random.choice([12, 48, 64, 108])}MP"
    #         },
    #         "Laptops": {
    #             "screen": f"{random.choice([13, 14, 15.6, 16])} inches",
    #             "storage": f"{random.choice([256, 512, 1024])}GB SSD",
    #             "ram": f"{random.choice([8, 16, 32])}GB",
    #             "processor": f"Core i{random.choice([5, 7, 9])}"
    #         }
    #     }.get(category, {"specs": "Basic specifications"})
        
    #     products.append({
    #         "id": i + 1,
    #         "name": f"{category} Pro {random.randint(1, 100)}",
    #         "category": category,
    #         "price": round(random.uniform(299.99, 2999.99), 2),
    #         "specs": specs,
    #         "stock": random.randint(0, 100),
    #         "rating": round(random.uniform(3.5, 5.0), 1)
    #     })
    
    return {"products": products}