Class StorageIngredientDB


  • public class StorageIngredientDB
    extends java.lang.Object
    The StorageIngredientDB class is a database for the storage ingredients.
    • Constructor Detail

      • StorageIngredientDB

        public StorageIngredientDB​(DBConnection connection)
        Creates a reference to the Firebase DB.
        Parameters:
        connection - the DBConnection object
    • Method Detail

      • addStorageIngredient

        public void addStorageIngredient​(@NonNull
                                         StorageIngredient storageIngredient,
                                         OnCompleteListener<StorageIngredient> listener)
        Adds an ingredient in storage to the Firebase DB.
        Parameters:
        storageIngredient - the ingredient to be added
        listener - the listener to be called when the operation is complete
      • updateStorageIngredient

        public void updateStorageIngredient​(StorageIngredient storageIngredient,
                                            OnCompleteListener<StorageIngredient> listener)
        Updates a stored ingredient in the Firebase DB.
        Parameters:
        storageIngredient - the Ingredient containing the updated fields
        listener - the listener to handle the result
      • updateStorageIngredient

        public void updateStorageIngredient​(StorageIngredient storageIngredient,
                                            StorageIngredient oldStorageIngredient,
                                            Ingredient ingredient,
                                            OnCompleteListener<StorageIngredient> listener)
        Updates a stored ingredient in the Firebase DB.
        Parameters:
        storageIngredient - the Ingredient containing the updated fields
        oldStorageIngredient - the old ingredient
        ingredient - the ingredient to be added
        listener - the listener to handle the result
      • deleteStorageIngredient

        public void deleteStorageIngredient​(StorageIngredient storageIngredient,
                                            OnCompleteListener<StorageIngredient> listener)
        Removes an ingredient from storage, but keeps the Ingredient reference
        Parameters:
        storageIngredient - the storageIngredient to remove
        listener - the listener to handle the result
      • getStorageIngredient

        public void getStorageIngredient​(java.lang.String id,
                                         OnCompleteListener<StorageIngredient> listener)
        Gets an ingredient from the Firebase DB
        Parameters:
        id - the ID of the ingredient to get a StorageIngredient with a null description. when the onComplete listener is interrupted
        listener - the listener to handle the result
      • getStorageIngredient

        public void getStorageIngredient​(com.google.firebase.firestore.DocumentSnapshot snapshot,
                                         OnCompleteListener<StorageIngredient> listener)
        Gets an ingredient from the Firebase DB
        Parameters:
        snapshot - the snapshot of the StorageIngredient to get
        listener - the listener to call when the ingredient is found
      • getSortedQuery

        public com.google.firebase.firestore.Query getSortedQuery​(java.lang.String field)
        Gets a sorted query for StorageIngredients in FireStore
        Parameters:
        field - the field to sort by
        Returns:
        the query
      • getSearchQuery

        public com.google.firebase.firestore.Query getSearchQuery​(java.lang.String field)
        getSearchedQuery returns a query for StorageIngredients in FireStore
        Parameters:
        field - the field to search by
        Returns:
        the query
      • getAllStorageIngredients

        public void getAllStorageIngredients​(OnCompleteListener<java.util.ArrayList<StorageIngredient>> listener)
        getAllStorageIngredients returns all StorageIngredients in FireStore
        Parameters:
        listener - the listener to handle the result