Appearance
Backend Feature: AddToCart
User story
As a visitor, I want to add products to my cart so that I can select items before placing an order.
Dependencies
- Entities: Cart, CartItem, Product
- API specs: POST /cart/items
Acceptance criteria
- [ ] Creates a new open cart for the
sessionIdif one does not exist. - [ ] Adds the product to the cart with the given quantity.
- [ ] If the product is already in the cart, sums the quantities.
- [ ]
quantitymust be at least 1; returns 400 otherwise. - [ ] Product must exist and not be soft-deleted; returns 422 otherwise.
- [ ] Returns 200 with the updated cart contents.
Edge cases
- First item added: cart is created and item inserted.
- Same product added again: existing cart item quantity is incremented.
- Invalid productId: returns 422.
quantityis 0 or negative: returns 400.
Notes
- The
sessionIdis always provided by the client — the API never generates it.