Class ShoppingCartDTO

java.lang.Object
com.goldenleaf.shop.dto.ShoppingCartDTO

public class ShoppingCartDTO extends Object
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:

  • totalPrice is calculated server-side — never trust client input!
  • customerId is derived from authentication context — not accepted from client
  • List of items is returned as unmodifiable to prevent external modification

Since:
1.0
  • Constructor Details

    • ShoppingCartDTO

      public ShoppingCartDTO()
      Required for JSON deserialization
    • ShoppingCartDTO

      public ShoppingCartDTO(Long id, Long customerId, List<ShoppingItemDTO> items, double totalPrice)
  • Method Details

    • getId

      public Long getId()
    • setId

      public void setId(Long id)
    • getCustomerId

      public Long getCustomerId()
    • setCustomerId

      public void setCustomerId(Long customerId)
    • getItems

      public List<ShoppingItemDTO> getItems()
      Returns an unmodifiable view of cart items. Ensures external code cannot modify the list after DTO creation.
    • setItems

      public void setItems(List<ShoppingItemDTO> items)
    • 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

      public String toString()
      Overrides:
      toString in class Object