I have an Android Studio project with 2 user collections: trainers and trainees. I want to make a method that receives the user's string email as input (the user's email is the document ID in both collections and a user can be either in the trainees collection or in the trainers collection not in both) and the method returns a boolean containing true if the user is a trainer and false if he isn't (meaning he is a trainee).
This is the code I came up with but its not working, it returns false all the time even if the user is a trainer. Am I doing something wrong? is there a better way to do this?
public static boolean isTrainer(String email)
{
FirebaseFirestore firestore = FirebaseFirestore.getInstance();
DocumentReference trainerRef = firestore.collection("trainers").document(email);
DocumentReference traineeRef = firestore.collection("trainees").document(email);
// Check if the trainer document exists
Task<DocumentSnapshot> trainerTask = trainerRef.get();
boolean isTrainer = trainerTask.isSuccessful() && trainerTask.getResult().exists();
// Check if the trainee document exists
Task<DocumentSnapshot> traineeTask = traineeRef.get();
boolean isTrainee = traineeTask.isSuccessful() && traineeTask.getResult().exists();
// If the trainer document exists but the trainee document doesn't, the user is a trainer
Log.d("FirestoreExample", "isTrainer: " + isTrainer + ", isTrainee: " + isTrainee);
return isTrainer && !isTrainee;
}
I tried many things but nothing worked