Class Product
java.lang.Object
com.goldenleaf.shop.model.Product
Represents a product available for purchase in the system. A product contains core details such as name, brand, price, categories, associated image URLs, and user reviews.
The class ensures validation of required fields such as product name, brand, and price, preventing creation of invalid product objects.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new review for this product.getBrand()getId()getName()doublegetPrice()voidSets a new product brand.voidsetCategories(Set<Category> categories) Sets the categories associated with this product.voidsetImageUrls(List<String> imageUrls) Sets the image URLs associated with this product.voidSets a new name for the product.voidsetPrice(double price) Sets the price of the product.voidsetReviews(List<Review> reviews) Sets the list of reviews for this product.
-
Constructor Details
-
Product
public Product()Default constructor required by JPA.
-
Product
public Product(String name, String brand, double price, Set<Category> categories, List<String> imageUrls, List<Review> reviews) throws EmptyBrandException, EmptyNameException, IncorrectPriceException Constructs a new product with the given parameters. Validates name, brand, and price before initialization.
- Parameters:
name- the name of the product; must not be null or blankbrand- the brand of the product; must not be null or blankprice- the price of the product; must not be negativecategories- categories assigned to this productimageUrls- associated image URLsreviews- initial list of reviews- Throws:
EmptyNameException- ifnameis null or blankEmptyBrandException- ifbrandis null or blankIncorrectPriceException- ifpriceis negative- See Also:
-
-
Method Details
-
getId
- Returns:
- the unique product identifier
-
getName
- Returns:
- the product name
-
setName
Sets a new name for the product.
- Parameters:
name- must not be null or blank- Throws:
EmptyNameException- ifnameis null or blank
-
getBrand
- Returns:
- the brand name
-
setBrand
-
getPrice
public double getPrice()- Returns:
- the product price
-
setPrice
public void setPrice(double price) Sets the price of the product.
- Parameters:
price- must not be negative
-
getCategories
-
setCategories
-
getImageUrls
-
setImageUrls
-
getReviews
-
setReviews
-
addReview
Adds a new review for this product.
- Parameters:
review- the review to add- See Also:
-