Package no.ntnu.idatt1002.demo.repo
Class InventoryRegister
java.lang.Object
no.ntnu.idatt1002.demo.repo.InventoryRegister
This class represents a register for inventory items.
Allowing for communication between the database and the user interface.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DAO
private List
<InventoryItem> private static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addInventoryItem
(int itemId, int quantity, String unit, int expirationDate) This method adds a new inventory item to the database.void
deleteInventoryItem
(int id) This method deletes an inventory item from the database.void
filterInventoryByCategory
(String category) This method retrieves filtered inventory items by category from the database.void
This method retrieves all inventory items from the database.private int
getIndexFromId
(int id) This method retrieves the index of an inventory item by its id.Returns the inventory items in the register in the form of lists.private void
packageToInventoryItems
(List<List<String>> inventoryItems) This method packages lists of lists representing inventory items into InventoryItem objects.void
searchInventoryByName
(String name) This method searches for inventory items by name and retrieves them from the database.void
updateInventoryItem
(int inventoryId, int itemId, int quantity, String unit, int expirationDate) This method updates an inventory item in the database.
-
Field Details
-
inventoryItems
-
dao
-
TABLE_NAME
- See Also:
-
-
Constructor Details
-
InventoryRegister
Constructor for the Inventory class.- Parameters:
dao
- the database access object- Throws:
IllegalArgumentException
- if the dao is null
-
-
Method Details
-
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
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
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
This method packages lists of lists representing inventory items into InventoryItem objects.- Parameters:
inventoryItems
- the list of lists representing inventory items
-
addInventoryItem
This method adds a new inventory item to the database.- Parameters:
itemId
- the id of the itemquantity
- the quantity of the itemunit
- the unit of the itemexpirationDate
- 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 itemitemId
- the id of the itemquantity
- the quantity of the itemunit
- the unit of the itemexpirationDate
- the expiration date of the item- Throws:
IllegalArgumentException
- if the id does not exist
-