From 518e1bbd941084ab35f1de3a873fa478cf09b1cc Mon Sep 17 00:00:00 2001 From: jermxt Date: Sun, 16 Oct 2022 17:04:30 +0000 Subject: [PATCH] added route to get all friends --- backend/users.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/users.py b/backend/users.py index 0c4f3a4..2d53b91 100644 --- a/backend/users.py +++ b/backend/users.py @@ -16,7 +16,7 @@ # username and password fields. If there is already # a user with the same username it returns { "success" : False} # -# post body: {"username" : USERNAME, "password", PASSWORD, "address" : ADDRESS, "phone" : PHONE} +# post body: {"name": NAME, "username" : USERNAME, "password", PASSWORD, "address" : ADDRESS, "phone" : PHONE} # returns: {"success" : BOOLEAN} @users_bp.route('/newUser/', methods=['POST']) def addUser(): @@ -26,7 +26,7 @@ def addUser(): lat, long = geocode(data['address']) session = Session() - newUser = User(username=data['username'], password=data['password'], \ + newUser = User(name=data['name'], username=data['username'], password=data['password'], \ friends=[], oncall=[], lat=lat, long=long, phone=data["phone"]) session.add(newUser) try: @@ -39,6 +39,17 @@ def addUser(): session.close() return jsonify(ret) +@users_bp.route('/allFriends/', methods=['GET']) +def getAllFriends(): + session = Session() + users = session.query(User.name, User.username).all() + session.close() + ret = [] + for a, b in users: + ret.append((a,b)) + return jsonify(ret) + + @users_bp.route('/login/', methods=['POST']) def loginUser(): data = request.json