Class InventoryRegister

java.lang.Object
no.ntnu.idatt1002.demo.repo.InventoryRegister

public class InventoryRegister extends Object
This class represents a register for inventory items. Allowing for communication between the database and the user interface.
  • Field Details

  • Constructor Details

    • InventoryRegister

      public InventoryRegister(DAO dao)
      Constructor for the Inventory class.
      Parameters:
      dao - the database access object
      Throws:
      IllegalArgumentException - if the dao is null
  • Method Details

    • getInventoryItems

      public List<InventoryItem> getInventoryItems()
      Returns the inventory items in the register in the form of lists.
      Returns:
      the inventory items in the register as lists of strings
    • getAllInventoryItems

      public void getAllInventoryItems()
      This method retrieves all inventory items from the database.
    • filterInventoryByCategory

      public void filterInventoryByCategory(String category)
      This method retrieves filtered inventory items by category from the database.
      Parameters:
      category - the category to filter by
      Throws:
      IllegalArgumentException - if category is empty
    • searchInventoryByName

      public void searchInventoryByName(String name)
      This method searches for inventory items by name and retrieves them from the database.
      Parameters:
      name - the name to search by
      Throws:
      IllegalArgumentException - if the name is empty
    • packageToInventoryItems

      private void packageToInventoryItems(List<List<String>> inventoryItems)
      This method packages lists of lists representing inventory items into InventoryItem objects.
      Parameters:
      inventoryItems - the list of lists representing inventory items
    • addInventoryItem

      public void addInventoryItem(int itemId, int quantity, String unit, int expirationDate)
      This method adds a new inventory item to the database.
      Parameters:
      itemId - the id of the item
      quantity - the quantity of the item
      unit - the unit of the item
      expirationDate - the expiration date of the item
    • getIndexFromId

      private int getIndexFromId(int id)
      This method retrieves the index of an inventory item by its id.
      Parameters:
      id - the id of the inventory item
      Returns:
      the index of the inventory item
    • deleteInventoryItem

      public void deleteInventoryItem(int id)
      This method deletes an inventory item from the database.
      Parameters:
      id - the id of the inventory item to delete
      Throws:
      IllegalArgumentException - if the id does not exist
    • updateInventoryItem

      public void updateInventoryItem(int inventoryId, int itemId, int quantity, String unit, int expirationDate)
      This method updates an inventory item in the database.
      Parameters:
      inventoryId - the id of the inventory item
      itemId - the id of the item
      quantity - the quantity of the item
      unit - the unit of the item
      expirationDate - the expiration date of the item
      Throws:
      IllegalArgumentException - if the id does not exist