Update code in endpoints/cart.post.py
This commit is contained in:
parent
d8f1ce2510
commit
cfc991d0cd
@ -0,0 +1,36 @@
|
||||
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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user