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).
What is the best way of doing this?
I tried many things like 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;
}
And other things but nothing worked.