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 7ef012a..b879634 100644 --- a/SE_API/ProjectRoutes.py +++ b/SE_API/ProjectRoutes.py @@ -140,13 +140,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

@@ -171,6 +172,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)) diff --git a/templates/js/controllers/myClassesController.js b/templates/js/controllers/myClassesController.js index 8ee23a8..6fc4029 100644 --- a/templates/js/controllers/myClassesController.js +++ b/templates/js/controllers/myClassesController.js @@ -12,6 +12,7 @@ angular.module('SeHub') $scope.user.startDate = ''; $scope.showMyClass = false; $scope.coursesEmpty = false; + $scope.campusId; var campusId = $routeParams.campusId; $scope.goToClass = function(classId) @@ -20,15 +21,16 @@ angular.module('SeHub') $location.path('/projects/' + classId.toString()); // Will display all the projects in this course } - $scope.chooseCourseClicked = function() + $scope.chooseCampusClicked = function() { $scope.isCourse = true; - console.log("choose course Clicked!!"); + console.log("Choose campus Clicked!!"); apiService.getAllCampuses(token).success(function(data) { $scope.campuses = data; - console.log("Campuses: " + $scope.campuses.toString()); + console.log("Campuses: "); + console.log($scope.campuses); }).error(function(err) { console.log("Error: " + err); @@ -42,12 +44,23 @@ angular.module('SeHub') $scope.submitNewClassClicked = function() { + var i; if($scope.course.courseName != null && $scope.course.endDate != null && $scope.course.startDate != null) { + for(i = 0; i < $scope.campuses.length; i++) + { + if($scope.course.campusName === $scope.campuses[i].title) + { + $scope.campusId = $scope.campuses[i].id; + } + } + console.log("NOW: "); + console.log($scope.campusId); + var jsonNewCourse = { 'courseName': $scope.course.courseName, - 'campusName': $scope.course.campusName, + 'campusId': $scope.campusId, 'startDate': { 'year' : $scope.course.startDate.getFullYear(), 'day' : $scope.course.startDate.getDate(), @@ -108,7 +121,7 @@ angular.module('SeHub') var displayCourses = function() { - apiService.getCourseByCampusName(token).success(function(data) // Shows all classes from this campus + apiService.getAllCoursesByCampus(token, campusId).success(function(data) // Shows all classes from this campus { $scope.courses = data; console.log("success " + $scope.courses); diff --git a/templates/js/controllers/registerController.js b/templates/js/controllers/registerController.js index 928bca6..5749b02 100644 --- a/templates/js/controllers/registerController.js +++ b/templates/js/controllers/registerController.js @@ -28,9 +28,9 @@ angular.module('SeHub') } apiService.getAllCampuses(token).success(function(data) // Get all the campuses - { - $scope.campuses = data; - }).error(function() { + { + $scope.campuses = data; + }).error(function() { // TODO }); }); diff --git a/templates/js/services/apiService.js b/templates/js/services/apiService.js index 8d14f27..d94388f 100644 --- a/templates/js/services/apiService.js +++ b/templates/js/services/apiService.js @@ -43,8 +43,8 @@ service.factory('apiService', ['$http', function($http) { }; return $http(req); }, - getCourseByCampusName: function(token){ - var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/courses/getCourseByCampusName/" + token; + getAllCoursesByCampus: function(token, campusId){ + var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/courses/getAllCoursesByCampus/" + token + '/' + campusId; req = { method : "GET", url : url diff --git a/templates/views/myClasses.html b/templates/views/myClasses.html index c9d2fd1..7764104 100644 --- a/templates/views/myClasses.html +++ b/templates/views/myClasses.html @@ -3,31 +3,30 @@

My Classes

-
-
+
-

{{course.title}}

+

{{course.courseName}}

- +
-

{{course.title}}

+

{{course.courseName}}

-
+
You Are Not Related To Any Course, You May Join Any Course You Wish.
@@ -57,7 +56,7 @@
- + {{c.title}} @@ -84,11 +83,11 @@
-
+