Class Customer
java.lang.Object
com.goldenleaf.shop.model.User
com.goldenleaf.shop.model.Customer
Entity representing a customer (registered user) of the online shop.
Extends the base User class and adds customer-specific attributes:
mobile phone, unique email, bonus points, a shopping cart and payment methods.
A customer can:
- accumulate and spend bonus points
- have exactly one active
ShoppingCart - attach multiple
CreditCards - leave
Reviews onProducts
- Since:
- 1.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBonusPoints(int bonuses) Adds the specified number of bonus points to the current balance.voidaddPayment(CreditCard card) Adds a credit card to the customer's payment methods and sets the bidirectional link.intReturns the current amount of bonus points.getEmail()Returns the customer's email address.Returns the customer's mobile phone number.Returns the list of payment cards linked to this customer.Returns the customer's shopping cart.voidmakeReview(Product product, String content, int rating) Creates and adds a review for the specified product.voidremovePayment(CreditCard card) Removes a credit card from the customer's payment methods and clears the bidirectional link.voidsetBonusPoints(int bonuses) Sets the exact amount of bonus points.voidSets a new email address.voidSets a new mobile phone number.voidsetShoppingCart(ShoppingCart shoppingCart) Assigns a shopping cart to this customer and establishes bidirectional relationship.Methods inherited from class com.goldenleaf.shop.model.User
getId, getLastActivity, getLogin, setLastActivity, setLogin, setPassword
-
Constructor Details
-
Customer
public Customer()Default constructor. Initializes bonus points to zero. -
Customer
public Customer(String login, String passwordHash, String name, LocalDate lastActivity, String mobile, String email, int bonusPoints, ShoppingCart shoppingCart, List<CreditCard> payments) throws IncorrectMobileException, IncorrectBonusPointsValue, IncorrectEmailException, EmptyShoppingCartException, NullPaymentException Full constructor creating a customer with all required fields.- Parameters:
login- user loginpasswordHash- hashed passwordname- customer's full namelastActivity- date of the last user activitymobile- mobile phone number (must be valid)email- email address (must be valid and unique)bonusPoints- initial bonus points (must be greater than or equal to 0)shoppingCart- customer's shopping cart (cannot benull)payments- list of payment cards (cannot benull)- Throws:
IncorrectMobileException- if the mobile number is invalidIncorrectEmailException- if the email address is invalidIncorrectBonusPointsValue- if bonus points are negativeEmptyShoppingCartException- if shopping cart isnullNullPaymentException- if the payments list isnull- See Also:
-
-
Method Details
-
getMobile
-
setMobile
Sets a new mobile phone number.- Parameters:
mobile- new mobile number- Throws:
IncorrectMobileException- if the provided mobile number is invalid
-
getEmail
-
setEmail
Sets a new email address.- Parameters:
email- new email address- Throws:
IncorrectEmailException- if the provided email is invalid
-
getBonusPoints
public int getBonusPoints()Returns the current amount of bonus points.- Returns:
- bonus points count
-
setBonusPoints
public void setBonusPoints(int bonuses) Sets the exact amount of bonus points.Only positive values are accepted; otherwise the operation is ignored.
- Parameters:
bonuses- new bonus points value (must be greater than 0)
-
addBonusPoints
public void addBonusPoints(int bonuses) Adds the specified number of bonus points to the current balance.Only positive values are added.
- Parameters:
bonuses- number of points to add (must be greater than 0)
-
getShoppingCart
Returns the customer's shopping cart.- Returns:
- associated
ShoppingCart, may benullif not yet assigned
-
setShoppingCart
Assigns a shopping cart to this customer and establishes bidirectional relationship.- Parameters:
shoppingCart- the shopping cart to set (can benullto detach)
-
getPayments
Returns the list of payment cards linked to this customer.- Returns:
- unmodifiable view of payment cards is not provided - direct list access
-
makeReview
public void makeReview(Product product, String content, int rating) throws IncorrectRatingException, EmptyAuthorException, EmptyContentException, EmptyProductException Creates and adds a review for the specified product.- Parameters:
product- the product being reviewed (cannot benull)content- review text (cannot be blank)rating- rating from 1 to 5- Throws:
IncorrectRatingException- if rating is not in range 1-5EmptyAuthorException- if author (current customer) is invalidEmptyContentException- if review content is blankEmptyProductException- if product isnull- See Also:
-
addPayment
Adds a credit card to the customer's payment methods and sets the bidirectional link.- Parameters:
card- the credit card to add (cannot benull)- Throws:
NullCustomerException- if the card's customer side cannot be set
-
removePayment
Removes a credit card from the customer's payment methods and clears the bidirectional link.- Parameters:
card- the credit card to remove- Throws:
NullCustomerException- if the card's customer reference cannot be cleared
-