Package com.xffffff.wellfed.shoppingcart
Class ShoppingCartDB
- java.lang.Object
-
- com.xffffff.wellfed.shoppingcart.ShoppingCartDB
-
public class ShoppingCartDB extends java.lang.ObjectThis class is the database for the shopping cart listIt is used to store the ingredients in the shopping cart list and to retrieve them It also contains methods to add and remove ingredients from the list
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceShoppingCartDB.OnPickedUpChangeonPickedUpChange is an interface for the updateIngredient method.
-
Constructor Summary
Constructors Constructor Description ShoppingCartDB(DBConnection connection)Constructor for the ShoppingCartDB.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddIngredient(Ingredient ingredient, OnCompleteListener<ShoppingCartIngredient> listener)Add an ingredient to the shopping cart.voidaddShoppingHelper(Ingredient ingredient, OnCompleteListener<ShoppingCartIngredient> listener)addShoppingHelper is a helper method for addIngredient.voiddeleteIngredient(ShoppingCartIngredient ingredient, OnCompleteListener<ShoppingCartIngredient> listener)Delete an ingredient from the shopping cart.voiddeleteIngredient(java.lang.String id, OnCompleteListener<ShoppingCartIngredient> listener)Delete all ingredients from the shopping cart.com.google.firebase.firestore.QuerygetQuery()Get a query of the shopping cart.com.google.firebase.firestore.QuerygetSearchQuery(java.lang.String field)Search the shopping cart by the given query string.voidgetShoppingCart(OnCompleteListener<java.util.ArrayList<ShoppingCartIngredient>> listener)Get the shopping cart.com.google.firebase.firestore.QuerygetSortedQuery(java.lang.String field)Sort the shopping cart by the given field.ShoppingCartIngredientsnapshotToShoppingCartIngredient(com.google.firebase.firestore.DocumentSnapshot doc)snapshot to shopping cart ingredient convertervoidupdateIngredient(ShoppingCartIngredient ingredient, OnCompleteListener<ShoppingCartIngredient> listener)Update an ingredient in the shopping cart.voidupdateIngredient(java.lang.String id, boolean isPickedUp, ShoppingCartDB.OnPickedUpChange listener)Update an ingredient in the shopping cart.
-
-
-
Constructor Detail
-
ShoppingCartDB
public ShoppingCartDB(DBConnection connection)
Constructor for the ShoppingCartDB.- Parameters:
connection- The DBConnection to use.
-
-
Method Detail
-
addIngredient
public void addIngredient(Ingredient ingredient, OnCompleteListener<ShoppingCartIngredient> listener)
Add an ingredient to the shopping cart.- Parameters:
ingredient- The ingredient to add to the shopping cart.listener- The listener to call when the ingredient is added.
-
addShoppingHelper
public void addShoppingHelper(Ingredient ingredient, OnCompleteListener<ShoppingCartIngredient> listener)
addShoppingHelper is a helper method for addIngredient.- Parameters:
ingredient- The ingredient to add to the shopping cart.listener- The listener to call when the ingredient is added.
-
updateIngredient
public void updateIngredient(ShoppingCartIngredient ingredient, OnCompleteListener<ShoppingCartIngredient> listener)
Update an ingredient in the shopping cart.- Parameters:
ingredient- The ingredient to update in the shopping cart.listener- The listener to call when the ingredient is updated.
-
updateIngredient
public void updateIngredient(java.lang.String id, boolean isPickedUp, ShoppingCartDB.OnPickedUpChange listener)Update an ingredient in the shopping cart.- Parameters:
id- The id of the ingredient to update in the shopping cart.isPickedUp- The boolean to set the ingredient to.listener- The listener to call when the ingredient is updated.
-
getShoppingCart
public void getShoppingCart(OnCompleteListener<java.util.ArrayList<ShoppingCartIngredient>> listener)
Get the shopping cart.- Parameters:
listener- The listener to call when the shopping cart is retrieved.
-
deleteIngredient
public void deleteIngredient(ShoppingCartIngredient ingredient, OnCompleteListener<ShoppingCartIngredient> listener)
Delete an ingredient from the shopping cart.- Parameters:
ingredient- The ingredient to delete from the shopping cart.listener- The listener to call when the ingredient is deleted.
-
deleteIngredient
public void deleteIngredient(java.lang.String id, OnCompleteListener<ShoppingCartIngredient> listener)Delete all ingredients from the shopping cart.- Parameters:
id- The id of the ingredient to delete from the shopping cart.listener- The listener to call when the ingredient is deleted.
-
getQuery
public com.google.firebase.firestore.Query getQuery()
Get a query of the shopping cart.- Returns:
- The query of the shopping cart.
-
getSortedQuery
public com.google.firebase.firestore.Query getSortedQuery(java.lang.String field)
Sort the shopping cart by the given field.- Parameters:
field- The category to sort by.- Returns:
- The query of the shopping cart.
-
getSearchQuery
public com.google.firebase.firestore.Query getSearchQuery(java.lang.String field)
Search the shopping cart by the given query string.- Parameters:
field- The query string.- Returns:
- The query of the shopping cart.
-
snapshotToShoppingCartIngredient
public ShoppingCartIngredient snapshotToShoppingCartIngredient(com.google.firebase.firestore.DocumentSnapshot doc)
snapshot to shopping cart ingredient converter- Parameters:
doc- snapshot- Returns:
- shopping cart ingredient
-
-