Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static List<User> getPayers(String bid) {
- List<User> users = new ArrayList<>();
- //asynchronously retrieve all documents
- ApiFuture<QuerySnapshot> future = db.collection("debts").document(bid).collection("payees").get();
- // future.get() blocks on response
- List<QueryDocumentSnapshot> documents = null;
- try {
- documents = future.get().getDocuments();
- } catch (InterruptedException e) {
- e.printStackTrace();
- } catch (ExecutionException e) {
- e.printStackTrace();
- }
- for (QueryDocumentSnapshot document : documents) {
- System.out.println(document.getId() + "\n");
- User u = new User(document.getId(), document.get("name").toString());
- users.add(u);
- }
- return users;
- }
- public static int getNumPayers(String bid) {
- return getPayers(bid).size();
- }
- public static List<String> getAllBids(String myUid) {
- List<String> bids = new ArrayList<>();
- //asynchronously retrieve all documents
- ApiFuture<QuerySnapshot> future = db.collection("debts").get();
- // future.get() blocks on response
- List<QueryDocumentSnapshot> documents = null;
- try {
- documents = future.get().getDocuments();
- } catch (InterruptedException e) {
- e.printStackTrace();
- } catch (ExecutionException e) {
- e.printStackTrace();
- }
- for (QueryDocumentSnapshot document : documents) {
- if (document.get("uid").toString().equals(myUid)) {
- System.out.println(document.getId() + "\n");
- bids.add(document.getId());
- }
- }
- return bids;
- }
- public static List<User> getAllPayers(String myUid) {
- List<String> bids = getAllBids(myUid);
- List<User> users = new ArrayList<>();
- for (String s: bids) {
- users.addAll(getPayers(s));
- }
- return users;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement