36 lines
746 B
Python
36 lines
746 B
Python
from fastapi import APIRouter, HTTPException
|
|
|
|
carts = [] # In-memory storage
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/cart")
|
|
async def add_to_cart(
|
|
user_id: str,
|
|
item_id: str,
|
|
quantity: int = 1
|
|
):
|
|
"""Add item to user's cart"""
|
|
cart = next((c for c in carts if c["user_id"] == user_id), None)
|
|
|
|
if not cart:
|
|
cart = {
|
|
"user_id": user_id,
|
|
"items": []
|
|
}
|
|
carts.append(cart)
|
|
|
|
cart["items"].append({
|
|
"item_id": item_id,
|
|
"quantity": quantity
|
|
})
|
|
|
|
return {
|
|
"message": "Item added to cart",
|
|
"cart_id": user_id,
|
|
"items": cart["items"],
|
|
"features": {
|
|
"max_items": 10,
|
|
"expires_in": 3600
|
|
}
|
|
} |