Class IngredientDB


  • public class IngredientDB
    extends java.lang.Object
    The IngredientDB class is used to store and retrieve ingredient data from the database.
    • Constructor Detail

      • IngredientDB

        public IngredientDB​(DBConnection connection)
        Constructs an IngredientDB object
        Parameters:
        connection - the DBConnection object to use
    • Method Detail

      • addIngredient

        public void addIngredient​(@NonNull
                                  Ingredient ingredient,
                                  OnCompleteListener<Ingredient> listener)
        Adds an ingredient in storage to the Firebase DB.
        Parameters:
        ingredient - the ingredient to add
        listener - the listener to call when the ingredient is added
      • getIngredient

        public void getIngredient​(java.lang.String id,
                                  OnCompleteListener<Ingredient> listener)
        Gets an ingredient from Firebase DB
        Parameters:
        id - the id of the ingredient to be retrieved
        listener - the listener to be called when the ingredient is retrieved
      • getIngredient

        public void getIngredient​(com.google.firebase.firestore.DocumentReference ingredientRef,
                                  OnCompleteListener<Ingredient> listener)
        Gets an ingredient from Firebase DB
        Parameters:
        ingredientRef - the DocumentReference of the ingredient to be retrieved
        listener - the listener to be called when the ingredient is retrieved
      • getIngredient

        public void getIngredient​(Ingredient ingredient,
                                  OnCompleteListener<Ingredient> listener)
        Gets an ingredient from Firebase DB
        Parameters:
        ingredient - the ingredient to be retrieved
        listener - the listener to be called when the ingredient is retrieved
      • deleteIngredient

        public void deleteIngredient​(@NonNull
                                     Ingredient ingredient,
                                     OnCompleteListener<Ingredient> listener)
        Deletes an ingredient from the Firebase DB.
        Parameters:
        ingredient - the ingredient to delete
        listener - the listener to call when the ingredient is deleted
      • updateReferenceCount

        public void updateReferenceCount​(Ingredient ingredient,
                                         int delta,
                                         OnCompleteListener<Ingredient> listener)
        Updates the reference count of an ingredient in the Firebase DB. The reference count keeps track of how many references exist to an object - if the object has 0 references, it is safely deleted.
        Parameters:
        ingredient - the ingredient to update the reference count of
        delta - how much to shift the reference count by
        listener - the listener to be called when the reference count is updated
      • snapshotToIngredient

        public Ingredient snapshotToIngredient​(com.google.firebase.firestore.DocumentSnapshot document)
        Converts a DocumentSnapshot of an ingredient to an Ingredient object
        Parameters:
        document - the DocumentSnapshot to convert
        Returns:
        the ingredient
      • getDocumentReference

        public com.google.firebase.firestore.DocumentReference getDocumentReference​(Ingredient ingredient)
        Get document reference of an ingredient
        Parameters:
        ingredient - the ingredient to get the reference of
        Returns:
        the document reference
      • getQuery

        public com.google.firebase.firestore.Query getQuery()
        Gets the CollectionReference that Ingredients are stored in
        Returns:
        the CollectionReference
      • getSortQuery

        public com.google.firebase.firestore.Query getSortQuery​(java.lang.String field,
                                                                boolean ascending)
      • getSearchQuery

        public com.google.firebase.firestore.Query getSearchQuery​(java.lang.String field)