Package com.xffffff.wellfed.mealplan
Class MealPlanDB
- java.lang.Object
-
- com.xffffff.wellfed.mealplan.MealPlanDB
-
public class MealPlanDB extends java.lang.Object
This class is used to access the meal plan database. It contains methods to add, remove, and update meal plans. It also contains methods to add, remove, and update recipes in meal plans.
-
-
Constructor Summary
Constructors Constructor Description MealPlanDB(DBConnection connection)
Constructor for class MealPlanDB, initializes declared fields.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMealPlan(MealPlan mealPlan, OnCompleteListener<MealPlan> listener)
This method is used to add a MealPlan object to the db.void
addMealPlanHelper(java.util.HashMap<java.lang.String,java.lang.Object> mealPlanMap, MealPlan mealPlan, java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> mealPlanIngredients, java.util.ArrayList<com.google.firebase.firestore.DocumentReference> mealPlanRecipes, OnCompleteListener<MealPlan> listener)
Helper function that adds the MealPlan document to db once all transactions are finished.void
addMealPlanIncrementCounter(java.util.HashMap<java.lang.String,java.lang.Object> mealPlanMap, MealPlan mealPlan, java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> mealPlanIngredients, java.util.ArrayList<com.google.firebase.firestore.DocumentReference> mealPlanRecipes, OnCompleteListener<MealPlan> listener)
addMealPlanIncrementCounter is a helper method for addMealPlan that increment counter for each recipe and ingredient in the MealPlan object.void
delMealPlan(MealPlan mealPlan, OnCompleteListener<MealPlan> listener)
Deletes the MealPlan object with the given id from the db.void
delMealPlanDecrementCounter(MealPlan mealPlan, com.google.firebase.firestore.DocumentReference mealPlanRef, OnCompleteListener<MealPlan> listener)
delMealPlanDecrementCounter is an asynchronous helper function for delMealPlan that decrements the counter of the ingredients and recipes in the MealPlan.void
delMealPlanHelper(MealPlan mealPlan, com.google.firebase.firestore.DocumentReference mealPlanRef, OnCompleteListener<MealPlan> listener)
delMealPlanHelper is a helper function for delMealPlanAsync.void
getMealPlan(com.google.firebase.firestore.DocumentSnapshot snapshot, OnCompleteListener<MealPlan> listener)
Gets the MealPlan object with the given id from the db.void
getMealPlan(java.lang.String id, OnCompleteListener<MealPlan> listener)
Gets the MealPlan object with the given id from the db.com.google.firebase.firestore.DocumentReference
getMealPlanDocumentReference(java.lang.String id)
Fet the DocumentReference object for the MealPlan document with the given id.void
getMealPlanHelper(MealPlan mealPlan, java.util.ArrayList<Ingredient> ingredients, java.util.ArrayList<Recipe> recipes, OnCompleteListener<MealPlan> listener)
Helper function for getMealPlan.MealPlanProxy
getMealPlanProxy(com.google.firebase.firestore.DocumentSnapshot snapshot)
Gets the MealPlan proxy object with the given snapshot from the db.void
getMealPlans(OnCompleteListener<java.util.ArrayList<MealPlan>> listener)
Get all MealPlan objects from the db.com.google.firebase.firestore.Query
getQuery()
Gets a query for MealPlans in the db.void
updateMealPlan(MealPlan mealPlan, OnCompleteListener<MealPlan> listener)
Updates the MealPlan object in the DBvoid
updateMealPlanDecrementCounter(MealPlan mealPlan, MealPlan foundMealPlan, OnCompleteListener<MealPlan> listener, java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> mealPlanIngredients, java.util.ArrayList<com.google.firebase.firestore.DocumentReference> mealPlanRecipes)
updateMealPlanDecrementCounter is a helper method for updateMealPlanAsync that decrements counter for recipes and ingredients in the MealPlan object.void
updateMealPlanFindOldMealPlan(MealPlan mealPlan, OnCompleteListener<MealPlan> listener, java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> mealPlanIngredients, java.util.ArrayList<com.google.firebase.firestore.DocumentReference> mealPlanRecipes)
updateMealPlanFindOldMealPlan is a helper method for updateMealPlan.void
updateMealPlanHelper(MealPlan mealPlan, OnCompleteListener<MealPlan> listener, java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> mealPlanIngredients, java.util.ArrayList<com.google.firebase.firestore.DocumentReference> mealPlanRecipes)
Given the MealPlan object, updates it in the db.void
updateMealPlanIncrementCounter(MealPlan mealPlan, MealPlan foundMealPlan, OnCompleteListener<MealPlan> listener, java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> mealPlanIngredients, java.util.ArrayList<com.google.firebase.firestore.DocumentReference> mealPlanRecipes)
updateMealPlanIncrementCounter is a helper method for updateMealPlanAsync that increments the counter for recipes and ingredients in the MealPlan object.void
updateMealPlanUpdateRecipes(MealPlan mealPlan, OnCompleteListener<MealPlan> listener, java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> mealPlanIngredients, java.util.ArrayList<com.google.firebase.firestore.DocumentReference> mealPlanRecipes)
updateMealPlanUpdateRecipes is a helper method for updateMealPlanAsync that updates the recipes in the MealPlan object.
-
-
-
Constructor Detail
-
MealPlanDB
public MealPlanDB(DBConnection connection)
Constructor for class MealPlanDB, initializes declared fields.- Parameters:
connection
- the DBConnection object used to access the db.
-
-
Method Detail
-
addMealPlan
public void addMealPlan(MealPlan mealPlan, OnCompleteListener<MealPlan> listener)
This method is used to add a MealPlan object to the db.- Parameters:
mealPlan
- the MealPlan object to be added to the db.listener
- the OnAddMealPlanListener object to handle the result.
-
addMealPlanIncrementCounter
public void addMealPlanIncrementCounter(java.util.HashMap<java.lang.String,java.lang.Object> mealPlanMap, MealPlan mealPlan, java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> mealPlanIngredients, java.util.ArrayList<com.google.firebase.firestore.DocumentReference> mealPlanRecipes, OnCompleteListener<MealPlan> listener)
addMealPlanIncrementCounter is a helper method for addMealPlan that increment counter for each recipe and ingredient in the MealPlan object.- Parameters:
mealPlanMap
- the HashMap to be used to map the MealPlan object.mealPlan
- the MealPlan object to be added to the db.mealPlanIngredients
- the ArrayList of HashMaps to be used to mapmealPlanRecipes
- the ArrayList of DocumentReferences to be used tolistener
- the OnAddMealPlanListener object to handle the result.
-
addMealPlanHelper
public void addMealPlanHelper(java.util.HashMap<java.lang.String,java.lang.Object> mealPlanMap, MealPlan mealPlan, java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> mealPlanIngredients, java.util.ArrayList<com.google.firebase.firestore.DocumentReference> mealPlanRecipes, OnCompleteListener<MealPlan> listener)
Helper function that adds the MealPlan document to db once all transactions are finished.- Parameters:
mealPlanMap
- the mapping of the MealPlan object.mealPlan
- the MealPlan object to be added to the db.mealPlanIngredients
- the ArrayList of HashMaps that stores the ingredients in the MealPlan object.mealPlanRecipes
- the ArrayList of DocumentReferences that stores the recipes in the MealPlan object.listener
- the OnAddMealPlanListener object to handle the result.
-
getMealPlan
public void getMealPlan(java.lang.String id, OnCompleteListener<MealPlan> listener)
Gets the MealPlan object with the given id from the db.- Parameters:
id
- the id of the MealPlan object to be retrieved.listener
- the OnGetMealPlanListener object to handle the result.
-
getMealPlanProxy
public MealPlanProxy getMealPlanProxy(com.google.firebase.firestore.DocumentSnapshot snapshot)
Gets the MealPlan proxy object with the given snapshot from the db.- Parameters:
snapshot
- the snapshot of the MealPlan proxy object to be retrieved.- Returns:
- the MealPlan proxy object with the given snapshot.
-
getMealPlan
public void getMealPlan(com.google.firebase.firestore.DocumentSnapshot snapshot, OnCompleteListener<MealPlan> listener)
Gets the MealPlan object with the given id from the db.- Parameters:
snapshot
- the snapshot of the MealPlan object to be retrieved.listener
- the OnGetMealPlanListener object to handle the result.
-
getMealPlanHelper
public void getMealPlanHelper(MealPlan mealPlan, java.util.ArrayList<Ingredient> ingredients, java.util.ArrayList<Recipe> recipes, OnCompleteListener<MealPlan> listener)
Helper function for getMealPlan.- Parameters:
mealPlan
- the MealPlan object to be returned.ingredients
- the ArrayList of ingredients to be added to the MealPlan object.recipes
- the ArrayList of recipes to be added to the MealPlan object.listener
- the OnGetMealPlanListener object to handle the result.
-
delMealPlan
public void delMealPlan(MealPlan mealPlan, OnCompleteListener<MealPlan> listener)
Deletes the MealPlan object with the given id from the db.- Parameters:
mealPlan
- the MealPlan object to be deleted.listener
- the OnDeleteMealPlanListener object to handle the result.
-
delMealPlanDecrementCounter
public void delMealPlanDecrementCounter(MealPlan mealPlan, com.google.firebase.firestore.DocumentReference mealPlanRef, OnCompleteListener<MealPlan> listener)
delMealPlanDecrementCounter is an asynchronous helper function for delMealPlan that decrements the counter of the ingredients and recipes in the MealPlan.- Parameters:
mealPlan
- the MealPlan object to be deleted.mealPlanRef
- the DocumentReference of the MealPlan object to belistener
- the OnDeleteMealPlanListener object to handle the result.
-
delMealPlanHelper
public void delMealPlanHelper(MealPlan mealPlan, com.google.firebase.firestore.DocumentReference mealPlanRef, OnCompleteListener<MealPlan> listener)
delMealPlanHelper is a helper function for delMealPlanAsync.- Parameters:
mealPlan
- the MealPlan object to be deleted.mealPlanRef
- the DocumentReference of the MealPlan object to be deleted.listener
- the OnDeleteMealPlanListener object to handle the result.
-
getMealPlans
public void getMealPlans(OnCompleteListener<java.util.ArrayList<MealPlan>> listener)
Get all MealPlan objects from the db.- Parameters:
listener
- the OnGetMealPlansListener object to handle the result.
-
updateMealPlan
public void updateMealPlan(MealPlan mealPlan, OnCompleteListener<MealPlan> listener)
Updates the MealPlan object in the DB- Parameters:
mealPlan
- the MealPlan object to be updated.listener
- the OnUpdateMealPlanListener object to handle the result.
-
updateMealPlanFindOldMealPlan
public void updateMealPlanFindOldMealPlan(MealPlan mealPlan, OnCompleteListener<MealPlan> listener, java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> mealPlanIngredients, java.util.ArrayList<com.google.firebase.firestore.DocumentReference> mealPlanRecipes)
updateMealPlanFindOldMealPlan is a helper method for updateMealPlan.- Parameters:
mealPlan
- the MealPlan object to be updated.listener
- the OnUpdateMealPlanListener object to handle the result.mealPlanIngredients
- the ArrayList of HashMaps of ingredients.mealPlanRecipes
- the ArrayList of DocumentReferences of recipes.
-
updateMealPlanIncrementCounter
public void updateMealPlanIncrementCounter(MealPlan mealPlan, MealPlan foundMealPlan, OnCompleteListener<MealPlan> listener, java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> mealPlanIngredients, java.util.ArrayList<com.google.firebase.firestore.DocumentReference> mealPlanRecipes)
updateMealPlanIncrementCounter is a helper method for updateMealPlanAsync that increments the counter for recipes and ingredients in the MealPlan object.- Parameters:
mealPlan
- the MealPlan object to be updated.foundMealPlan
- the MealPlan object found in the db.listener
- the OnUpdateMealPlanListener object to handle the result.mealPlanIngredients
- the ArrayList of HashMaps of ingredients.mealPlanRecipes
- the ArrayList of DocumentReferences of recipes.
-
updateMealPlanDecrementCounter
public void updateMealPlanDecrementCounter(MealPlan mealPlan, MealPlan foundMealPlan, OnCompleteListener<MealPlan> listener, java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> mealPlanIngredients, java.util.ArrayList<com.google.firebase.firestore.DocumentReference> mealPlanRecipes)
updateMealPlanDecrementCounter is a helper method for updateMealPlanAsync that decrements counter for recipes and ingredients in the MealPlan object.- Parameters:
mealPlan
- the MealPlan object to be updated.foundMealPlan
- the MealPlan object found in the db.listener
- the OnUpdateMealPlanListener object to handle the result.mealPlanIngredients
- the ArrayList of HashMaps of ingredients.mealPlanRecipes
- the ArrayList of DocumentReferences of recipes.
-
updateMealPlanUpdateRecipes
public void updateMealPlanUpdateRecipes(MealPlan mealPlan, OnCompleteListener<MealPlan> listener, java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> mealPlanIngredients, java.util.ArrayList<com.google.firebase.firestore.DocumentReference> mealPlanRecipes)
updateMealPlanUpdateRecipes is a helper method for updateMealPlanAsync that updates the recipes in the MealPlan object.- Parameters:
mealPlan
- the MealPlan object to be updated.listener
- the OnUpdateMealPlanListener object to handle the result.mealPlanIngredients
- the ArrayList of HashMaps of ingredients.mealPlanRecipes
- the ArrayList of DocumentReferences of recipes.
-
updateMealPlanHelper
public void updateMealPlanHelper(MealPlan mealPlan, OnCompleteListener<MealPlan> listener, java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> mealPlanIngredients, java.util.ArrayList<com.google.firebase.firestore.DocumentReference> mealPlanRecipes)
Given the MealPlan object, updates it in the db.- Parameters:
mealPlan
- the MealPlan object to be updated.listener
- the OnUpdateMealPlanListener object to handle the result.mealPlanIngredients
- the ArrayList of Ingredient objects to be updated.mealPlanRecipes
- the ArrayList of Recipe objects to be updated.
-
getMealPlanDocumentReference
public com.google.firebase.firestore.DocumentReference getMealPlanDocumentReference(java.lang.String id)
Fet the DocumentReference object for the MealPlan document with the given id.- Parameters:
id
- the id of the MealPlan document.- Returns:
- the DocumentReference object for the MealPlan document.
-
getQuery
public com.google.firebase.firestore.Query getQuery()
Gets a query for MealPlans in the db.- Returns:
- the query for MealPlans in the db.
-
-