Class UserDB

java.lang.Object
com.example.breeze_seas.UserDB

public class UserDB extends Object
This class provides methods to create, update, delete, and retrieve users using the device's unique ID as the primary key.
  • Constructor Details

    • UserDB

      public UserDB()
  • Method Details

    • createUser

      public com.google.android.gms.tasks.Task<Void> createUser(User user)
      Creates a new user record in the database. If the document already exists, it merges the new data with existing fields. Sets the createdAt timestamp to the server time.
      Parameters:
      user - The User object containing the profile data to be stored.
    • updateUser

      public void updateUser(String deviceId, Map<String,Object> updates)
      Updates specific fields of an existing user document. Automatically appends an updatedAt server timestamp to the request.
      Parameters:
      deviceId - The unique identifier of the user to update.
      updates - A Map containing field names as keys and the new values to be updated.
    • updateUser

      public void updateUser(String deviceId, Map<String,Object> updates, @Nullable UserDB.UserMutationCallback callback)
      Updates specific fields of an existing user document and reports the result.
      Parameters:
      deviceId - The unique identifier of the user to update.
      updates - A Map containing field names as keys and the new values to be updated.
      callback - Optional callback receiving success or failure.
    • deleteUser

      public void deleteUser(String deviceId)
      Deletes all trace of the user from the database except comments.
      Parameters:
      deviceId - The unique identifier of the user to be deleted.
    • startUsersListen

      public void startUsersListen(UserDB.UsersChangedCallback callback)
      Starts listening to the "users" collection in real time. Any add, modify, or remove on any user document will fire the appropriate callback.
      Parameters:
      callback - Receives individual change events or errors.
    • stopUsersListen

      public void stopUsersListen()
      Stops listener for the "users" collection.
    • getUser

      public void getUser(String deviceId, UserDB.OnUserLoadedListener listener)
      Fetches a user document from Firestore. Results are returned via the provided UserDB.OnUserLoadedListener.
      Parameters:
      deviceId - The unique identifier of the user to fetch.
      listener - The callback listener to handle the retrieved data or errors.