|
9 | 9 |
|
10 | 10 | @router.get("/") |
11 | 11 | def root() -> dict: |
12 | | - """Return a structured welcome message for the API root, including product data.""" |
| 12 | + """Return product data.""" |
13 | 13 | load_dotenv() |
14 | | - conn = psycopg2.connect( |
15 | | - host=os.getenv('DB_HOST'), |
16 | | - port=os.getenv('DB_PORT', '5432'), |
17 | | - dbname=os.getenv('DB_NAME'), |
18 | | - user=os.getenv('DB_USER'), |
19 | | - password=os.getenv('DB_PASSWORD') |
20 | | - ) |
21 | | - cur = conn.cursor() |
22 | | - cur.execute('SELECT id, name, description, price, in_stock, created_at FROM product;') |
23 | | - products = [ |
24 | | - { |
25 | | - "id": row[0], |
26 | | - "name": row[1], |
27 | | - "description": row[2], |
28 | | - "price": float(row[3]), |
29 | | - "in_stock": row[4], |
30 | | - "created_at": row[5].isoformat() if row[5] else None |
31 | | - } |
32 | | - for row in cur.fetchall() |
33 | | - ] |
34 | | - cur.close() |
35 | | - conn.close() |
| 14 | + base_url = os.getenv("BASE_URL", "http://localhost:8000") |
36 | 15 | epoch = int(time.time() * 1000) |
37 | 16 | meta = { |
38 | 17 | "version": __version__, |
39 | 18 | "time": time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), |
40 | 19 | "epoch": epoch, |
41 | 20 | "severity": "success", |
42 | | - "message": f"NX AI says hello & returned {len(products)} products" |
| 21 | + "message": f"NX AI says hello", |
| 22 | + "base_url": base_url |
43 | 23 | } |
44 | | - return {"meta": meta, "data": products} |
| 24 | + endpoints = [ |
| 25 | + {"name": "health", "url": f"{base_url}/health"}, |
| 26 | + {"name": "products", "url": f"{base_url}/products"} |
| 27 | + ] |
| 28 | + return {"meta": meta, "data": endpoints} |
0 commit comments