From 0e37e51b4df6e07ee965c1ce767af358856c53cb Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Fri, 26 Jun 2015 14:55:08 +0300 Subject: [PATCH] API: Added Get User By ID --- SE_API/UserRoutes.py | 60 ++++++++++++++++++++++++++++++++++++++ SE_API/Validation_Utils.py | 4 +++ 2 files changed, 64 insertions(+) diff --git a/SE_API/UserRoutes.py b/SE_API/UserRoutes.py index a448ae6..54f19a8 100644 --- a/SE_API/UserRoutes.py +++ b/SE_API/UserRoutes.py @@ -268,6 +268,66 @@ def getUserByToken(token): status=200, mimetype="application/json") # Real response! + return no_content("No User Found") + +@user_routes.route('/api/users/getUserById/', defaults={'token': None, 'id': None}) +@user_routes.route('/api/users/getUserById//', methods=["GET"]) +@auto.doc() +def getUserById(token, id): + """ + >This Call will return a user by a given UserId +
+ Route Parameters
+ - seToken: 'seToken' +
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ + {
+ 'username': 'DarkLord',
+ 'name': 'Darth Vader',
+ 'email': 'darkLord@death.planet,
+ 'isLecturer': 'True',
+ 'seToken': 'xxxxxx-xxxxx-xxxxx-xxxxxx',
+ 'avatar_url': 'http://location.git.com/somthing'
+ 'isFirstLogin': False,
+ 'campuses_id_list': [{
+ 'master_user_id': 111,
+ 'id': 5629499534213120,
+ 'email_ending': "@post.jce.ac.il",
+ 'avatar_url': "https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg",
+ 'title': "JCE" + }],
+ 'courses_id_list': ['a','b','c'],
+ 'id': 234253523
+ }
+
+
+ 403 - No User Found + """ + if token is None or id is None: + return no_content("No Token/ID, No User Found") + + if get_user_by_token(token) is None: + return forbidden('Invalid Token') + + u = get_user_by_id(int(id)) + if u is None: + return no_content('No user Found') + + for index, c in enumerate(u.campuses_id_list): + c = json.loads(Campus.get_by_id(int(c)).to_JSON()) + u.campuses_id_list[index] = c + + return Response(response=u.to_JSON(), + status=200, + mimetype="application/json") # Real response! return no_content("No User Found") diff --git a/SE_API/Validation_Utils.py b/SE_API/Validation_Utils.py index 56da380..b6c0937 100644 --- a/SE_API/Validation_Utils.py +++ b/SE_API/Validation_Utils.py @@ -13,6 +13,10 @@ def get_user_by_token(token): return u return None +def get_user_by_id(id): + u = User.get_by_id(id) + return u + def get_campus_by_campusName(campusName): query = Campus.all() query.filter("title = ", campusName)