Class InventorySQL
java.lang.Object
csce331.group13.project2.backend.InventorySQL
Provides data access methods for inventory items in the database.
Handles all CRUD operations for the inventory table.
- Author:
- Varish Kongara
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanAdds a new inventory item to the database.static booleandeleteInventoryItem(UUID itemId) Deletes an inventory item from the database by its unique identifier.static List<InventoryItem> Retrieves all inventory items from the database.static Optional<InventoryItem> getInventoryItemById(UUID itemId) Retrieves an inventory item by its unique identifier.static voidreduceInventory(UUID menuItemId, int quantity) Reduces the stock of inventory items associated with a menu item.static booleanUpdates an existing inventory item in the database.
-
Constructor Details
-
InventorySQL
public InventorySQL()
-
-
Method Details
-
getAllInventoryItems
Retrieves all inventory items from the database.- Returns:
- A list of all InventoryItem objects, sorted alphabetically by item name.
-
addInventoryItem
Adds a new inventory item to the database.- Parameters:
item- The InventoryItem to add.- Returns:
- true if the item was successfully added; false otherwise.
-
updateInventoryItem
Updates an existing inventory item in the database.- Parameters:
item- The InventoryItem with updated values.- Returns:
- true if the update was successful; false otherwise.
-
deleteInventoryItem
Deletes an inventory item from the database by its unique identifier.- Parameters:
itemId- The UUID of the inventory item to delete.- Returns:
- true if the deletion was successful; false otherwise.
-
getInventoryItemById
Retrieves an inventory item by its unique identifier.- Parameters:
itemId- The UUID of the inventory item to retrieve.- Returns:
- An Optional containing the InventoryItem if found, or empty if not found.
-
reduceInventory
Reduces the stock of inventory items associated with a menu item. Uses the menu_inventory_relationship table to determine which inventory items are used and by how much.- Parameters:
menuItemId- The UUID of the menu item whose inventory should be reduced.quantity- The number of menu items ordered.- Throws:
SQLException- if a database error occurs during the update.
-