42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from core.database import fake_users_db
|
|
from core.auth import get_current_user_dummy
|
|
|
|
router = APIRouter()
|
|
|
|
# Demo cart data
|
|
fake_cart_db = {
|
|
"demo": [
|
|
{"id": "1", "name": "Product 1", "price": 29.99, "quantity": 2},
|
|
{"id": "2", "name": "Product 2", "price": 19.99, "quantity": 1}
|
|
]
|
|
}
|
|
|
|
@router.get("/cart")
|
|
async def get_cart_items(
|
|
current_user: dict = Depends(get_current_user_dummy)
|
|
):
|
|
"""Get list of items in user's cart"""
|
|
username = current_user.get("username", "demo")
|
|
|
|
if username not in fake_cart_db:
|
|
return {
|
|
"message": "Cart is empty",
|
|
"items": [],
|
|
"metadata": {
|
|
"total_items": 0,
|
|
"total_value": 0.00
|
|
}
|
|
}
|
|
|
|
cart_items = fake_cart_db[username]
|
|
total_value = sum(item["price"] * item["quantity"] for item in cart_items)
|
|
|
|
return {
|
|
"message": "Cart items retrieved successfully",
|
|
"items": cart_items,
|
|
"metadata": {
|
|
"total_items": len(cart_items),
|
|
"total_value": total_value
|
|
}
|
|
} |