Package no.ntnu.idatt1002.demo.repo
Class RecipeRegister
java.lang.Object
no.ntnu.idatt1002.demo.repo.RecipeRegister
This class represents a register for recipes.
Allowing for communication between the database and the user interface.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addIngredient
(int itemId, int quantity, String unit, int recipeId) Adds an ingredient to the database.void
addInstruction
(int recipeId, int stepNumber, String instruction) This method adds an instruction to the database.void
This method adds a recipe to the database.void
deleteIngredient
(int id) This method deletes an ingredient from the database.void
deleteInstruction
(int id) Deletes an instruction from the database.void
deleteRecipe
(int id) This method deletes a recipe from the database.void
filterRecipesByCategory
(String category) This method retrieves filtered recipes by category from the database.void
This method retrieves all recipes from the database.Returns the recipes in the register in the form of lists.int
getRecipesFromId
(int id) Retrieves the index of a recipe from the register by id.private void
instructionNumbering
(int recipeId, int step, boolean add) This method adjusts step numbers when an instruction is changed.private void
packagetoRecipe
(List<List<String>> recipes) This method packages the recipes into a list of recipes.void
searchRecipesByName
(String name) This method searches for recipes by name and retrieves them from the database.toString()
Returns a string representation of the recipe register.void
updateIngredient
(int recipeIngredientId, int itemId, int quantity, String unit) This method updates an ingredient in the database.void
updateInstrucution
(int stepId, int stepNumber, String instruction) This method updates an instruction in the database.void
updateRecipe
(int recipeId, String name, int cookingTime, String category) This method updates a recipe in the database.
-
Field Details
-
recipes
-
dao
-
-
Constructor Details
-
RecipeRegister
Constructor for the RecipeRegister class.- Parameters:
dao
- the data access object
-
-
Method Details
-
getRecipes
Returns the recipes in the register in the form of lists.- Returns:
- the recipes in the register as lists of strings
-
packagetoRecipe
This method packages the recipes into a list of recipes.- Parameters:
recipes
- the recipes to package
-
filterRecipesByCategory
This method retrieves filtered recipes by category from the database.- Parameters:
category
- the category to filter by
-
searchRecipesByName
This method searches for recipes by name and retrieves them from the database.- Parameters:
name
- the name to search by
-
getAllRecipes
public void getAllRecipes()This method retrieves all recipes from the database. -
addRecipe
This method adds a recipe to the database.- Parameters:
name
- the name of the recipecategory
- the category of the recipecookingTime
- the cooking time of the recipe
-
getRecipesFromId
public int getRecipesFromId(int id) Retrieves the index of a recipe from the register by id.- Parameters:
id
- the id of the recipe- Returns:
- the index of the recipe
-
deleteRecipe
public void deleteRecipe(int id) This method deletes a recipe from the database.- Parameters:
id
- the id of the recipe to delete
-
updateRecipe
This method updates a recipe in the database.- Parameters:
recipeId
- the id of the recipename
- the name of the recipecookingTime
- the cooking time of the recipecategory
- the category of the recipe
-
addIngredient
Adds an ingredient to the database.- Parameters:
itemId
- the id of the itemquantity
- the quantity of the itemunit
- the unit of the itemrecipeId
- the id of the recipe
-
deleteIngredient
public void deleteIngredient(int id) This method deletes an ingredient from the database.- Parameters:
id
- the id of the ingredient to delete
-
updateIngredient
This method updates an ingredient in the database.- Parameters:
recipeIngredientId
- the id of the recipe ingredientitemId
- the id of the itemquantity
- the quantity of the itemunit
- the unit of the item
-
addInstruction
This method adds an instruction to the database.- Parameters:
recipeId
- the id of the recipestepNumber
- the number of the stepinstruction
- the instruction of the step
-
deleteInstruction
public void deleteInstruction(int id) Deletes an instruction from the database.- Parameters:
id
- the id of the instruction to delete
-
updateInstrucution
This method updates an instruction in the database.- Parameters:
stepId
- the id of the stepstepNumber
- the number of the stepinstruction
- the instruction
-
instructionNumbering
private void instructionNumbering(int recipeId, int step, boolean add) This method adjusts step numbers when an instruction is changed.- Parameters:
step
- the step numberadd
- whether to add or subtractrecipe_id
- the id of the recipe
-
toString
Returns a string representation of the recipe register.
-