Class TheCookbookDB
java.lang.Object
edu.ntnu.stud.idatt1005.team3.database.TheCookbookDB
A class that provides methods for interacting with the database.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addObserver
(ObserverDB observer) Deletes a food item from the database.void
Deletes the placeholder recipe from the database once if new recipe hasn't been made.Retrieves all recipes from the database and puts them in a list.Retrieves all food items from the database and puts them in a list.getFoodItem
(String name) Retrieves a food item from the database.int
getFoodItemId
(String name) Retrieves the ID of a food item from the database.double
getFoodItemQuantity
(FoodItem foodItem) Retrieves all the categories from the database og a chosen recipe and puts them in a list.getIngredientAsFoodItem
(int recipeId, String foodItemName) Retrieves the ID of a category from the database.int
getIngredientId
(String name, int recipeId) Retrieves the ID of an ingredient from the database.getIngredientsAsFoodItemList
(int recipeId) Retrieves the ingredients for a recipe as a list of FoodItem objects.getIngredientsForRecipe
(int recipe_id) Retrieves all the ingredients from the database og a chosen recipe and puts them in a list.Retrieves all food items from the database that have a quantity greater than 0.Retrieves a recipe from the database.int
getRecipeId
(String name) Retrieves the ID of a recipe from the database.int
getRecipeIdFromIngredientId
(int ingredientId) Gets the recipe id for an ingredient.getStepsForRecipe
(int recipe_id) Retrieves all steps from the database og a chosen recipe and puts them in a list.void
insertFoodItem
(String name, double quantity, String unit) Inserting a new FoodItem to the database.void
insertIngredient
(int food_item_id, int recipe_id, double quantity, String unit) Inserts a new ingredient to the database, where we can connect it to a food item and a recipe.void
Inserts a placeholder recipe to the database.void
insertRecipe
(String name, int servings) Inserting a new recipe to the database.void
insertRecipeCategory
(int recipe_id, String name) Inserts a new category to the database, where we can connect it to a recipe.void
insertStep
(int step_number, String description, int recipe_id) Inserting a step in the recipe.void
Notifies all observers that the database has been updated.void
removeFoodItem
(String name) Removes a food item from the database.void
removeIngredient
(String name, int recipeId) Removes an ingredient from the database.void
removeObserver
(ObserverDB observer) Deletes a food item from the database.void
removeRecipe
(int id) Deletes a recipe from the database.void
updateFoodItem
(FoodItem foodItem, double quantity) Updates the quantity of a food item in the database.void
updateFoodItemQuantity
(int foodItemId, double newQuantity) Updates the quantity of a food item in the database.void
updatePlaceholderRecipe
(int id, String name, int servings) Updates the placeholder recipe to a proper new recipe in the NewRecipePage.
-
Constructor Details
-
TheCookbookDB
public TheCookbookDB()
-
-
Method Details
-
insertFoodItem
Inserting a new FoodItem to the database.- Parameters:
name
- the name of the itemquantity
- the current quantity of the itemunit
- the unit used to measure the item
-
insertRecipe
Inserting a new recipe to the database.- Parameters:
name
- the name of the recipeservings
- the amount of serving the recipe will make
-
insertIngredient
Inserts a new ingredient to the database, where we can connect it to a food item and a recipe.- Parameters:
food_item_id
- a reference to the ingredient in the FoodItem tablerecipe_id
- a reference to the recipe the ingredient will be used forquantity
- the quantity used in the recipeunit
- the unit used for measurement in the recipe
-
insertRecipeCategory
Inserts a new category to the database, where we can connect it to a recipe.- Parameters:
recipe_id
- a reference to the recipe the category will be used forname
- the name of the category
-
insertStep
Inserting a step in the recipe.- Parameters:
step_number
- the number of the step in the recipedescription
- what to do in the current steprecipe_id
- the recipe the step is used for
-
getRecipe
Retrieves a recipe from the database.- Parameters:
recipeName
- the name of the recipe you want to retrieve- Returns:
- returning the chosen recipe id, name and servings, and then gets the steps and ingredients with their own method using the id
-
getAllRecipeNames
Retrieves all recipes from the database and puts them in a list.- Returns:
- a list that contains the names of all recipes
-
getAllRecipes
Retrieves all food items from the database and puts them in a list.- Returns:
- Returns a list of all food items.
-
getStepsForRecipe
Retrieves all steps from the database og a chosen recipe and puts them in a list.- Parameters:
recipe_id
- the id of the recipe you want to view- Returns:
- a list of the steps for the recipe
-
getFoodItem
Retrieves a food item from the database.- Parameters:
name
- The name of the food item you want to retrieve- Returns:
- The chosen food item
-
getIngredientsForRecipe
Retrieves all the ingredients from the database og a chosen recipe and puts them in a list.- Parameters:
recipe_id
- The id of the recipe you want to view- Returns:
- Returns a list of the ingredients for the recipe
-
getFoodItemQuantity
Retrieves all the categories from the database og a chosen recipe and puts them in a list.- Parameters:
foodItem
- The id of the recipe you want to view.- Returns:
- Returns a list of the categories for the recipe.
-
updateFoodItemQuantity
public void updateFoodItemQuantity(int foodItemId, double newQuantity) Updates the quantity of a food item in the database.- Parameters:
foodItemId
- The ID of the food item to update.newQuantity
- The new quantity of the food item.
-
getNonEmptyFoodItems
Retrieves all food items from the database that have a quantity greater than 0.- Returns:
- A list of all food items with quantity greater than 0.
-
clearPlaceholder
public void clearPlaceholder()Deletes the placeholder recipe from the database once if new recipe hasn't been made. -
removeRecipe
public void removeRecipe(int id) Deletes a recipe from the database.- Parameters:
id
- The ID of the recipe to delete.
-
addObserver
Deletes a food item from the database.- Parameters:
observer
- The food item to delete.
-
insertPlaceholderRecipe
public void insertPlaceholderRecipe()Inserts a placeholder recipe to the database. -
getRecipeId
Retrieves the ID of a recipe from the database.- Parameters:
name
- The name of the recipe whose ID you want to retrieve.
-
getFoodItemId
Retrieves the ID of a food item from the database.- Parameters:
name
- The name of the food item whose ID you want to retrieve.- Returns:
- Returns the ID of the food item.
-
removeFoodItem
Removes a food item from the database.- Parameters:
name
- The name of the food item to remove.
-
getIngredientId
Retrieves the ID of an ingredient from the database.- Parameters:
name
- The name of the ingredient whose ID you want to retrieve.recipeId
- The ID of the recipe the ingredient is used in.- Returns:
- Returns the ID of the ingredient.
-
getIngredientAsFoodItem
Retrieves the ID of a category from the database.- Parameters:
recipeId
- The ID of the recipe the category is used in.foodItemName
- The name of the category whose ID you want to retrieve.- Returns:
- Returns the ID of the category.
-
getIngredientsAsFoodItemList
Retrieves the ingredients for a recipe as a list of FoodItem objects.- Parameters:
recipeId
- The ID of the recipe the ingredient is used in.- Returns:
- Returns the list of ingredients.
-
getRecipeIdFromIngredientId
public int getRecipeIdFromIngredientId(int ingredientId) Gets the recipe id for an ingredient.- Parameters:
ingredientId
- The id of the ingredient.- Returns:
- Returns the recipe id.
-
updateFoodItem
Updates the quantity of a food item in the database.- Parameters:
foodItem
- The food item to update.quantity
- The new quantity of the food item.
-
removeIngredient
Removes an ingredient from the database.- Parameters:
name
- The name of the ingredient to remove.recipeId
- The ID of the recipe the ingredient is used in.
-
updatePlaceholderRecipe
Updates the placeholder recipe to a proper new recipe in the NewRecipePage.- Parameters:
id
- The ID of the recipe to update.name
- The name of the recipe to update.servings
- The amount of servings for the recipe.
-
removeObserver
Deletes a food item from the database.- Parameters:
observer
- The observer to remove.
-
notifyObservers
public void notifyObservers()Notifies all observers that the database has been updated.
-