Class InventorySQL

java.lang.Object
csce331.group13.project2.backend.InventorySQL

public class InventorySQL extends Object
Provides data access methods for inventory items in the database. Handles all CRUD operations for the inventory table.
Author:
Varish Kongara
  • Constructor Details

    • InventorySQL

      public InventorySQL()
  • Method Details

    • getAllInventoryItems

      public static List<InventoryItem> getAllInventoryItems()
      Retrieves all inventory items from the database.
      Returns:
      A list of all InventoryItem objects, sorted alphabetically by item name.
    • addInventoryItem

      public static boolean addInventoryItem(InventoryItem item)
      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

      public static boolean updateInventoryItem(InventoryItem item)
      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

      public static boolean deleteInventoryItem(UUID itemId)
      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

      public static Optional<InventoryItem> getInventoryItemById(UUID itemId)
      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

      public static void reduceInventory(UUID menuItemId, int quantity) throws SQLException
      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.