Class ShoppingCartService
java.lang.Object
com.goldenleaf.shop.service.ShoppingCartService
Service class for managing
ShoppingCart entities.
Provides business logic for retrieving, adding, updating, and deleting shopping carts.
Supports operations by Customer and cart ID.
Acts as an intermediary between controllers and the ShoppingCartRepository.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newShoppingCartServicewith the provided repository. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddShoppingCart(ShoppingCart cart) Adds a newShoppingCartto the database.voideditShoppingCart(ShoppingCart cart) Updates an existingShoppingCart.Retrieves all shopping carts from the database.getShoppingCartByCustomer(Customer customer) Retrieves aShoppingCartfor a specificCustomer.Retrieves aShoppingCartby its unique ID.voidRemoves an existingShoppingCartfrom the database.voidremoveShoppingCartByCustomer(Customer customer) Removes aShoppingCartassociated with a specificCustomer.voidRemoves aShoppingCartby its ID.
-
Constructor Details
-
ShoppingCartService
Constructs a newShoppingCartServicewith the provided repository.- Parameters:
repo- the repository used to perform operations on shopping carts- Throws:
IllegalArgumentException- ifrepoisnull- See Also:
-
-
Method Details
-
getAllShoppingCarts
Retrieves all shopping carts from the database.- Returns:
- a
Listof allShoppingCartentities - See Also:
-
getShoppingCartById
Retrieves aShoppingCartby its unique ID.- Parameters:
id- the ID of the shopping cart- Returns:
- the
ShoppingCartwith the specified ID - Throws:
RuntimeException- if no shopping cart with the given ID exists- See Also:
-
getShoppingCartByCustomer
Retrieves aShoppingCartfor a specificCustomer.- Parameters:
customer- the customer whose shopping cart is retrieved- Returns:
- the
ShoppingCartfor the given customer - Throws:
RuntimeException- if no shopping cart exists for the given customer- See Also:
-
addShoppingCart
Adds a newShoppingCartto the database.- Parameters:
cart- the shopping cart to add- See Also:
-
removeShoppingCart
Removes an existingShoppingCartfrom the database.If the shopping cart exists (by ID), it will be deleted; otherwise, nothing happens.
- Parameters:
cart- the shopping cart to remove- See Also:
-
removeShoppingCartById
Removes aShoppingCartby its ID.- Parameters:
id- the ID of the shopping cart to delete- See Also:
-
removeShoppingCartByCustomer
Removes aShoppingCartassociated with a specificCustomer.- Parameters:
customer- the customer whose shopping cart should be deleted- Throws:
EmptyLoginException- if no shopping cart exists for the given customer- See Also:
-
editShoppingCart
Updates an existingShoppingCart.The shopping cart must have a valid ID that exists in the database. Otherwise, a
RuntimeExceptionis thrown.- Parameters:
cart- the shopping cart to update- Throws:
RuntimeException- if the shopping cart does not exist or ID is null- See Also:
-