Class RecipeRegister

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

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

    • recipes

      private List<Recipe> recipes
    • dao

      private final DAO dao
  • Constructor Details

    • RecipeRegister

      public RecipeRegister(DAO dao)
      Constructor for the RecipeRegister class.
      Parameters:
      dao - the data access object
  • Method Details

    • getRecipes

      public Map<Integer,Recipe> getRecipes()
      Returns the recipes in the register in the form of lists.
      Returns:
      the recipes in the register as lists of strings
    • packagetoRecipe

      private void packagetoRecipe(List<List<String>> recipes)
      This method packages the recipes into a list of recipes.
      Parameters:
      recipes - the recipes to package
    • filterRecipesByCategory

      public void filterRecipesByCategory(String category)
      This method retrieves filtered recipes by category from the database.
      Parameters:
      category - the category to filter by
    • searchRecipesByName

      public void searchRecipesByName(String name)
      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

      public void addRecipe(String name, String category, int cookingTime)
      This method adds a recipe to the database.
      Parameters:
      name - the name of the recipe
      category - the category of the recipe
      cookingTime - 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

      public void updateRecipe(int recipeId, String name, int cookingTime, String category)
      This method updates a recipe in the database.
      Parameters:
      recipeId - the id of the recipe
      name - the name of the recipe
      cookingTime - the cooking time of the recipe
      category - the category of the recipe
    • addIngredient

      public void addIngredient(int itemId, int quantity, String unit, int recipeId)
      Adds an ingredient to the database.
      Parameters:
      itemId - the id of the item
      quantity - the quantity of the item
      unit - the unit of the item
      recipeId - 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

      public void updateIngredient(int recipeIngredientId, int itemId, int quantity, String unit)
      This method updates an ingredient in the database.
      Parameters:
      recipeIngredientId - the id of the recipe ingredient
      itemId - the id of the item
      quantity - the quantity of the item
      unit - the unit of the item
    • addInstruction

      public void addInstruction(int recipeId, int stepNumber, String instruction)
      This method adds an instruction to the database.
      Parameters:
      recipeId - the id of the recipe
      stepNumber - the number of the step
      instruction - 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

      public void updateInstrucution(int stepId, int stepNumber, String instruction)
      This method updates an instruction in the database.
      Parameters:
      stepId - the id of the step
      stepNumber - the number of the step
      instruction - 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 number
      add - whether to add or subtract
      recipe_id - the id of the recipe
    • toString

      public String toString()
      Returns a string representation of the recipe register.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the recipe register