diff --git a/SE_API/CourseRoutes.py b/SE_API/CourseRoutes.py index 07c9101..c651a60 100644 --- a/SE_API/CourseRoutes.py +++ b/SE_API/CourseRoutes.py @@ -169,9 +169,9 @@ def joinCourse(token, courseId): #---------------------------------------------------------- -@course_routes.route('/api/courses/getCoursesByCampus/', methods=["GET"]) +@course_routes.route('/api/courses/getAllCoursesByCampus//', methods=["GET"]) @auto.doc() -def getCourseByCampus(campusId): +def getAllCoursesByCampus(token, campusId): """ >This Call will return an array of all courses in a given campus
@@ -199,6 +199,10 @@ def getCourseByCampus(campusId):
""" + + if get_user_by_token(token) is None: + return bad_request("Bad User Token") + arr = [] query = Course.all() query.filter("campusId = ", int(campusId)) @@ -215,11 +219,11 @@ def getCourseByCampus(campusId): status=200, mimetype="application/json") -@course_routes.route('/api/courses/getCoursesByUser//', methods=['GET']) +@course_routes.route('/api/courses/getUserCoursesByCampus//', methods=['GET']) @auto.doc() -def getCampusesByUser(token, campusId): +def getUserCoursesByCampus(token, campusId): """ - This Call will return an array of all Campuses of a certain User + This Call will return an array of all Courses of a certain User in a specific Campus
Route Parameters
- seToken: 'seToken'
@@ -275,6 +279,63 @@ def getCampusesByUser(token, campusId): mimetype="application/json") +@course_routes.route('/api/courses/getCoursesByUser//', methods=['GET']) +@auto.doc() +def getCoursesByUser(token, userId): + """ + This Call will return an array of all Courses of a certain User +
+ Route Parameters
+ - seToken: 'seToken'
+ - userId: 1234354543
+
+
+ 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") + + otherUser = User.get_by_id(int(userId)) + if otherUser is None: + return bad_request("Bad user Id") + + arr = [] + for i in otherUser.courses_id_list: + print i + course = Course.get_by_id(int(i)) + arr.append(dict(json.loads(course.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") #---------------------------------------------------------- # PUT #---------------------------------------------------------- diff --git a/SE_API/ProjectRoutes.py b/SE_API/ProjectRoutes.py index 80a7839..e9e57b8 100644 --- a/SE_API/ProjectRoutes.py +++ b/SE_API/ProjectRoutes.py @@ -138,13 +138,14 @@ def joinProject(token, projectId): # GET #---------------------------------------------------------- -@project_routes.route('/api/projects/getProjectsByCourse/', methods=["GET"]) +@project_routes.route('/api/projects/getProjectsByCourse//', methods=["GET"]) @auto.doc() -def getProjectsByCourse(courseId): +def getProjectsByCourse(token, courseId): """ >This Call will return an array of all projects in a given course
Route Parameters
+ - seToken: token
- courseId: 1234567890

@@ -169,6 +170,8 @@ def getProjectsByCourse(courseId):
""" + if get_user_by_token(token) is None: + return bad_request("Bad User Token") arr = [] query = Project.all() query.filter("courseId = ", int(courseId))