diff --git a/SE_API/CampusRoutes.py b/SE_API/CampusRoutes.py index c49fb3e..02d460e 100644 --- a/SE_API/CampusRoutes.py +++ b/SE_API/CampusRoutes.py @@ -192,7 +192,65 @@ def getCampusesByUser(token): return bad_request("Bad user Token") arr = [] - for i in user['campuses_id_list']: + 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") + +@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()))) 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) diff --git a/templates/API_Doc/api_doc_index.html b/templates/API_Doc/api_doc_index.html index a1077de..e1b4ae1 100644 --- a/templates/API_Doc/api_doc_index.html +++ b/templates/API_Doc/api_doc_index.html @@ -54,8 +54,8 @@ SE-Hub Docs Index - -
+
+
  • Users Related API
  • Campuses Related API
  • @@ -66,7 +66,7 @@
  • Miscellaneous Methods
- +