From 330304cd4ca6b46301cb8454eaee2fd783fb529f Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Wed, 24 Jun 2015 19:57:40 +0300 Subject: [PATCH] added getCampusesByUser function --- SE_API/CampusRoutes.py | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/SE_API/CampusRoutes.py b/SE_API/CampusRoutes.py index 6f73148..efb92ac 100644 --- a/SE_API/CampusRoutes.py +++ b/SE_API/CampusRoutes.py @@ -153,6 +153,58 @@ def get_campuses(token): return forbidden("Invalid Token") +@campus_routes.route('/api/campuses/getCampusesByUser/', methods=['GET']) +@auto.doc() +def getCampusesByUser(token): + """ + This Call will return an array of all Campuses of a certain User +
+ Route Parameters
+ - seToken: 'seToken' +
+
+ Payload
+ - NONE
+
+
+ Response +
+ 200 - JSON Array, Example:
+ [
+ { + 'title': 'JCE',
+ 'email_ending': '@post.jce.ac.il',
+ 'master_user_id': 123453433341, (User that created the campus)
+ 'avatar_url': 'http://some.domain.com/imagefile.jpg',
+ 'id' : 1234567890
+ },
+ ....
+ {
+ ...
+ }req
+ ]
+
+ 403 - Invalid Token
+ """ + + user = get_user_by_token(token) + if user is None: + return bad_request("Bad user Token") + + arr = [] + for i in user['campuses_id_list']: + campus = Campus.get_by_id(int(i)) + arr.append(dict(json.loads(campus.to_JSON()))) + + if len(arr) != 0: + return Response(response=json.dumps(arr), + status=200, + mimetype="application/json") + else: + return Response(response=[], + status=200, + mimetype="application/json") + #---------------------------------------------------------- # DELETE #----------------------------------------------------------