The cart (E-commerce Store (full stack))
Each user has a cart. POST /cart {"product","qty"} (qty 1–99, default 1) adds → 201 {"cart":…}; PATCH /cart/<id {"qty"} sets it (0 removes) → 200; DELETE /cart/<id → 200; GET /cart → 200. A cart is {"items":[{"line","name","price","product","qty"}],"subtotal"} in the order items were added. Errors: unknown product 404, more than in stock 409 {"error":"only <n in stock"}, not in cart 404 {"error":"not in cart"}, bad JSON 400 {"error":"bad json"}, bad qty 400 {"error":"qty must be a whole number from <1 or 0 to 99"}, missing fields 400 {"error":"bad body"}.
Input: As before.
Output: As before.
Difficulty: Medium. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.
Hint
- Store only product ids and quantities; compute names, prices and totals when you answer.