Class Menu

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

public class Menu extends Object
Singleton class that manages the in-memory menu cache. Provides methods to access, update, and manage menu items and their inventory relationships.
Author:
Austin Glander, Varish Kongara, William Clymire
  • Field Details

  • Constructor Details

    • Menu

      public Menu()
      Private constructor that initializes the menu by loading all menu items and their inventory relationships from the database.
  • Method Details

    • getInstance

      public static Menu getInstance()
      Returns the singleton instance of the Menu class.
      Returns:
      The single Menu instance.
    • updateMenuItem

      public boolean updateMenuItem(MenuItem menuItem)
      Updates a menu item in the database.
      Parameters:
      menuItem - The MenuItem with updated values.
      Returns:
      true if the update was successful; false otherwise.
    • categorizeMenuItems

      public Map<String, List<MenuItem>> categorizeMenuItems()
      Organizes all menu items into a map by category.
      Returns:
      A map where keys are category names (Combo, Entree, Side, Drink, AddOn) and values are lists of MenuItem objects in each category.
    • getMenuItemByName

      public MenuItem getMenuItemByName(String name)
      Retrieves a menu item by its name (case-insensitive). First searches the in-memory cache, then falls back to the database if not found.
      Parameters:
      name - The name of the menu item to find.
      Returns:
      The MenuItem with the given name, or null if not found.
    • getItemsByCategoryName

      public List<String> getItemsByCategoryName(String category)
      Retrieves all active menu item names for a specific category.
      Parameters:
      category - The category to filter by (e.g., "Entree", "Side", "Drink").
      Returns:
      A list of item names in the specified category.
    • addMenuItemWithInventory

      public void addMenuItemWithInventory(MenuItem menuItem, List<InventoryItem> inventoryItems, List<BigDecimal> quantities)
      Adds a new menu item along with its inventory relationships. This operation is transactional - either all changes succeed or all are rolled back.
      Parameters:
      menuItem - The MenuItem to add.
      inventoryItems - List of InventoryItem objects required for this menu item.
      quantities - List of quantities corresponding to each inventory item.
    • updateMenuItemWithInventory

      public void updateMenuItemWithInventory(MenuItem menuItem, List<InventoryItem> inventoryItems, List<BigDecimal> quantities)
      Updates a menu item and its inventory relationships. Deletes existing relationships and creates new ones. This operation is transactional - either all changes succeed or all are rolled back.
      Parameters:
      menuItem - The MenuItem with updated values.
      inventoryItems - List of InventoryItem objects required for this menu item.
      quantities - List of quantities corresponding to each inventory item.
    • getInventoryItemsForMenuItem

      public List<InventoryItem> getInventoryItemsForMenuItem(UUID menuItemId)
      Retrieves all inventory items associated with a specific menu item.
      Parameters:
      menuItemId - The UUID of the menu item.
      Returns:
      A list of InventoryItem objects used by this menu item.
    • getQuantitiesForMenuItem

      public List<BigDecimal> getQuantitiesForMenuItem(UUID menuItemId)
      Retrieves the quantities of each inventory item required for a specific menu item.
      Parameters:
      menuItemId - The UUID of the menu item.
      Returns:
      A list of BigDecimal quantities corresponding to the inventory items.