From 1c32ed9e56fc79eeb2f4da53ea265303ee58ac34 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Fri, 26 Jun 2015 15:07:26 +0300 Subject: [PATCH] API: Added /api/campuses/getCampusesByUserID/ --- SE_API/CampusRoutes.py | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/SE_API/CampusRoutes.py b/SE_API/CampusRoutes.py index 594975c..02d460e 100644 --- a/SE_API/CampusRoutes.py +++ b/SE_API/CampusRoutes.py @@ -205,6 +205,64 @@ def getCampusesByUser(token): status=200, mimetype="application/json") +@campus_routes.route('/api/campuses/getCampusesByUserID/', defaults={'token': None, 'id': None}) +@campus_routes.route('/api/campuses/getCampusesByUserID//', methods=['GET']) +@auto.doc() +def getCampusesByUserID(token, id): + """ + This Call will return an array of all Campuses of a certain User By ID +
+ Route Parameters
+ - token: 'seToken' of requesting user + - The ID of Wanted User Campuses +
+
+ 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 forbidden("Invalid Token") + + user = get_user_by_id(int(id)) + if user is None: + return no_content("No User") + + 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 #----------------------------------------------------------