Class ShoppingCartDTO
java.lang.Object
com.goldenleaf.shop.dto.ShoppingCartDTO
Data Transfer Object representing a customer's shopping cart.
Used in:
- GET /api/cart — returning current cart state
- Mini-cart widget in header
- Checkout page — final review before order
- Service layer → controller communication
Important:
totalPriceis calculated server-side — never trust client input!customerIdis derived from authentication context — not accepted from client- List of items is returned as unmodifiable to prevent external modification
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionRequired for JSON deserializationShoppingCartDTO(Long id, Long customerId, List<ShoppingItemDTO> items, double totalPrice) -
Method Summary
Modifier and TypeMethodDescriptiongetId()getItems()Returns an unmodifiable view of cart items.doublevoidsetCustomerId(Long customerId) voidvoidsetItems(List<ShoppingItemDTO> items) voidsetTotalPrice(double totalPrice) Total price is calculated on the server.toString()
-
Constructor Details
-
ShoppingCartDTO
public ShoppingCartDTO()Required for JSON deserialization -
ShoppingCartDTO
-
-
Method Details
-
getId
-
setId
-
getCustomerId
-
setCustomerId
-
getItems
Returns an unmodifiable view of cart items. Ensures external code cannot modify the list after DTO creation. -
setItems
-
getTotalPrice
public double getTotalPrice() -
setTotalPrice
public void setTotalPrice(double totalPrice) Total price is calculated on the server. This setter should only be used internally or in mapping. -
toString
-