Class ShoppingCartDB


  • public class ShoppingCartDB
    extends java.lang.Object
    This class is the database for the shopping cart list

    It 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

    • 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