Class ShoppingItemDTO

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

public class ShoppingItemDTO extends Object
Data Transfer Object representing a single item in the shopping cart.

Used exclusively in ShoppingCartDTO responses. Contains read-only data about the product and its current state in the cart.

Important security rules:

  • All price-related fields are calculated server-side — never trust client input
  • Quantity is validated against stock during add/update operations
  • This DTO is output-only — never used for input from client

Since:
1.0
  • Constructor Details

    • ShoppingItemDTO

      public ShoppingItemDTO()
      Required for JSON deserialization
    • ShoppingItemDTO

      public ShoppingItemDTO(Long id, Long productId, String productName, int quantity, double pricePerUnit)
  • Method Details

    • getId

      public Long getId()
    • setId

      public void setId(Long id)
    • getProductId

      public Long getProductId()
    • setProductId

      public void setProductId(Long productId)
    • getProductName

      public String getProductName()
    • setProductName

      public void setProductName(String productName)
    • getQuantity

      public int getQuantity()
    • setQuantity

      public void setQuantity(int quantity)
    • getPricePerUnit

      public double getPricePerUnit()
    • setPricePerUnit

      public void setPricePerUnit(double pricePerUnit)
    • getSubtotal

      public double getSubtotal()
      Calculates subtotal for this item. Convenience method for frontend or logging.
      Returns:
      quantity × pricePerUnit, rounded to 2 decimal places
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object