Guest User

Review QUERY!

a guest
Dec 15th, 2019
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. func writeToDB(UID: String, restName: String, numberOfDiners: Int, experience: String, goBack: String, dishInfo: [(String, Double, String, String)]) {
  2.  
  3.     let restPath = "restaurant/" + restName + "/reviews"
  4.     let dishPath = "menu/" + restName + "/"
  5.     let reviewPath = "review data/" + restName + "/" + UID
  6.  
  7.     Database.database().reference().child(restPath).setValue([UID: experience])
  8.     Database.database().reference().child(reviewPath).setValue(["Number of Diners": numberOfDiners, "Would you go back": goBack])
  9.  
  10.     for dish in dishInfo {
  11.         Database.database().reference().child(dishPath).observeSingleEvent(of: .value) { snapshot in
  12.             if (snapshot.hasChild(dish.0)) {
  13.                 Database.database().reference().child(dishPath + dish.0 + "/user reviews/" + UID).setValue(["rating": dish.1, "text review": dish.2, "image": dish.3])
  14.  
  15.             } else {
  16.                 Database.database().reference().child(dishPath + dish.0).setValue(["section": "main"])
  17.                 Database.database().reference().child(dishPath + dish.0 + "/user reviews/" + UID).setValue(["rating": dish.1, "text review": dish.2, "image": dish.3])
  18.             }
  19.         }
  20.     }
  21. }
RAW Paste Data