Class ShoppingItemService
java.lang.Object
com.goldenleaf.shop.service.ShoppingItemService
Service class for managing
ShoppingItem entities.
Provides business logic for retrieving, adding, updating, and deleting shopping items.
Supports operations by ShoppingCart and Product.
Acts as an intermediary between controllers and the ShoppingItemRepository.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newShoppingItemServicewith the provided repository. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddShoppingItem(ShoppingItem item) Adds a newShoppingItemto the database.voideditShoppingItem(ShoppingItem item) Updates an existingShoppingItem.Retrieves all shopping items from the database.Retrieves aShoppingItemby its unique ID.Retrieves all shopping items in a specific shopping cart.voidRemoves an existingShoppingItemfrom the database.voidRemoves aShoppingItemby its ID.voidremoveShoppingItemByProduct(Product product) Removes aShoppingItemassociated with a specificProduct.
-
Constructor Details
-
ShoppingItemService
Constructs a newShoppingItemServicewith the provided repository.- Parameters:
repo- the repository used to perform operations on shopping items- Throws:
IllegalArgumentException- ifrepoisnull- See Also:
-
-
Method Details
-
getAllShoppingItems
Retrieves all shopping items from the database.- Returns:
- a
Listof allShoppingItementities - See Also:
-
getShoppingItemsByCart
Retrieves all shopping items in a specific shopping cart.- Parameters:
cart- theShoppingCartwhose items are retrieved- Returns:
- a
ListofShoppingItemin the cart - See Also:
-
getShoppingItemById
Retrieves aShoppingItemby its unique ID.- Parameters:
id- the ID of the shopping item- Returns:
- the
ShoppingItemwith the specified ID - Throws:
RuntimeException- if no shopping item with the given ID exists- See Also:
-
addShoppingItem
Adds a newShoppingItemto the database.- Parameters:
item- the shopping item to add- See Also:
-
removeShoppingItem
Removes an existingShoppingItemfrom the database.If the shopping item exists (by ID), it will be deleted; otherwise, nothing happens.
- Parameters:
item- the shopping item to remove- See Also:
-
removeShoppingItemById
Removes aShoppingItemby its ID.- Parameters:
id- the ID of the shopping item to delete- See Also:
-
removeShoppingItemByProduct
Removes aShoppingItemassociated with a specificProduct.- Parameters:
product- the product whose shopping item should be deleted- Throws:
RuntimeException- if no shopping item exists for the given product- See Also:
-
editShoppingItem
Updates an existingShoppingItem.The shopping item must have a valid ID that exists in the database. Otherwise, a
RuntimeExceptionis thrown.- Parameters:
item- the shopping item to update- Throws:
RuntimeException- if the shopping item does not exist or ID is null- See Also:
-