diff --git a/SE_API/API.py b/SE_API/API.py index 327d7ed..4918e46 100644 --- a/SE_API/API.py +++ b/SE_API/API.py @@ -139,12 +139,12 @@ def send_activation(token): return Response(status=200) @app.route('/api/help') -def documentation(): +def documentation_index(): return app.send_static_file('API_Doc/api_doc_index.html') -# @app.route('/api/help/campuses') -# def documentation(): -# return auto.html() +@app.route('/api/help/misc') +def documentation_misc(): + return auto.html() @app.route('/home') def returnHome(): 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/CourseRoutes.py b/SE_API/CourseRoutes.py index e4e1c8c..1585d28 100644 --- a/SE_API/CourseRoutes.py +++ b/SE_API/CourseRoutes.py @@ -259,7 +259,7 @@ def getCampusesByUser(token, campusId): arr = [] - for i in user['courses_id_list']: + for i in user.courses_id_list: course = Course.get_by_id(int(i)) if course.campusId == campus.key().id(): arr.append(dict(json.loads(course.to_JSON()))) @@ -269,7 +269,7 @@ def getCampusesByUser(token, campusId): status=200, mimetype="application/json") else: - return Response(response=[], + return Response(response='[]', status=200, mimetype="application/json") diff --git a/SE_API/UserRoutes.py b/SE_API/UserRoutes.py index 4a7f35e..57a107e 100644 --- a/SE_API/UserRoutes.py +++ b/SE_API/UserRoutes.py @@ -269,6 +269,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/models/User.py b/models/User.py index d3bb545..bb60c2b 100644 --- a/models/User.py +++ b/models/User.py @@ -27,6 +27,7 @@ class User(db.Model): 'campusName': self.campusName, 'campuses_id_list': self.campuses_id_list, 'courses_id_list': self.courses_id_list, - 'projects_id_list': self.projects_id_list + 'projects_id_list': self.projects_id_list, + 'id' : self.key().id() } return json.dumps(data) diff --git a/templates/API_Doc/api_doc_index.html b/templates/API_Doc/api_doc_index.html index c69ffb2..9a1111f 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
  • @@ -64,9 +64,10 @@
  • Tasks Related API
  • Messages Related API
  • Validation Related API
  • +
  • Miscellaneous Methods
- +