diff --git a/SE_API/CourseRoutes.py b/SE_API/CourseRoutes.py index 578b36c..e4e1c8c 100644 --- a/SE_API/CourseRoutes.py +++ b/SE_API/CourseRoutes.py @@ -49,7 +49,7 @@ def create_course(token): - JSON Object, Example:
{
'courseName': 'Advance Math',
- 'campusName': 'JCE',
+ 'campusId': 1234567890,
'startDate': {'year': 2015, 'month' : 4, 'day' : 3},
'endDate': {'year': 2016, 'month' : 5, 'day' : 14}
}
@@ -83,7 +83,7 @@ def create_course(token): if end_date <= start_date: return bad_request("end date cant be before (or same day) start date") - course = Course(courseName=payload['courseName'], campusName=payload['campusName'], master_id=user.key().id(), + course = Course(courseName=payload['courseName'], campusId=payload['campusId'], master_id=user.key().id(), startDate=start_date, endDate=end_date) #check if name already exists try: @@ -168,14 +168,14 @@ def joinCourse(token, courseId): #---------------------------------------------------------- -@course_routes.route('/api/courses/getCourseByCampusName/', methods=["GET"]) +@course_routes.route('/api/courses/getCoursesByCampus/', methods=["GET"]) @auto.doc() -def getCourseByCampusName(name): +def getCourseByCampus(campusId): """ >This Call will return an array of all courses in a given campus
Route Parameters
- - name: 'campus name' + - campusId: 1234567890

Payload
@@ -188,7 +188,7 @@ def getCourseByCampusName(name): {
'courseName': 'Advance Math',
- 'campusName': 'JCE',
+ 'campusId': 1234567890,
'startDate': '2015-14-3'
'endDate': '2015-29-6'
'taskFlag': 'False'
@@ -200,7 +200,7 @@ def getCourseByCampusName(name): """ arr = [] query = Course.all() - query.filter("campusName=", name) + query.filter("campusId = ", int(campusId)) for c in query.run(): arr.append(dict(json.loads(c.to_JSON()))) @@ -261,7 +261,7 @@ def getCampusesByUser(token, campusId): arr = [] for i in user['courses_id_list']: course = Course.get_by_id(int(i)) - if course.courseName == campus.title: + if course.campusId == campus.key().id(): arr.append(dict(json.loads(course.to_JSON()))) if len(arr) != 0: @@ -289,7 +289,7 @@ def getCampusesByUser(token, campusId): @course_routes.route('/api/courses/deleteCourse//', methods=['DELETE']) @auto.doc() -def deleteCourse(token,courseid): +def deleteCourse(token, courseid): """ This Call will delete a specific Course
@@ -335,64 +335,64 @@ def deleteCourse(token,courseid): return forbidden("lecturer is not owner of course") -@course_routes.route('/api/courses/deleteCoursesByCampus//', methods=['DELETE']) -@auto.doc() -def deleteCoursesByCampus(token,campusName): - """ - This Call will delete a specific campus's courses -
- Route Parameters
- - seToken: 'seToken' - - title: 'campusName' -
-
- Payload
- - NONE
-
-
- Response -
- 202 - Deleted campus -
- 204 - No Matching Campus Found -
- ....
- {
- ...
- }req
- - ]
- 400 - Bad Request -
- 403 - Invalid token or not a lecturer!
- """ - - if not is_lecturer(token): #todo: change to lecturer id - return forbidden("Invalid token or not a lecturer!") - - - user = get_user_by_token(token) - campus = get_campus_by_campusName(campusName) - if campus is None: - return bad_request("Not a campus!") - - #check user is owner of campus - if campus.master_user_id != user.key().id(): - return forbidden("lecturer is not owner of campus!") - - query = Course.all() - - try: - query.filter('campusName =', campusName) - except Exception as e: - print e - return bad_request("invalid course title attribute") - - for c in query.run(): - db.delete(c) - db.save - - return no_content() +# @course_routes.route('/api/courses/deleteCoursesByCampus//', methods=['DELETE']) +# @auto.doc() +# def deleteCoursesByCampus(token,campusName): +# """ +# This Call will delete a specific campus's courses +#
+# Route Parameters
+# - seToken: 'seToken' +# - title: 'campusName' +#
+#
+# Payload
+# - NONE
+#
+#
+# Response +#
+# 202 - Deleted campus +#
+# 204 - No Matching Campus Found +#
+# ....
+# {
+# ...
+# }req
+# +# ]
+# 400 - Bad Request +#
+# 403 - Invalid token or not a lecturer!
+# """ +# +# if not is_lecturer(token): #todo: change to lecturer id +# return forbidden("Invalid token or not a lecturer!") +# +# +# user = get_user_by_token(token) +# campus = get_campus_by_campusName(campusName) +# if campus is None: +# return bad_request("Not a campus!") +# +# #check user is owner of campus +# if campus.master_user_id != user.key().id(): +# return forbidden("lecturer is not owner of campus!") +# +# query = Course.all() +# +# try: +# query.filter('campusName =', campusName) +# except Exception as e: +# print e +# return bad_request("invalid course title attribute") +# +# for c in query.run(): +# db.delete(c) +# db.save +# +# return no_content() diff --git a/SE_API/ProjectRoutes.py b/SE_API/ProjectRoutes.py index 80d1d02..80a7839 100644 --- a/SE_API/ProjectRoutes.py +++ b/SE_API/ProjectRoutes.py @@ -42,7 +42,7 @@ def create_project(token): - JSON Object, Example:
{
'projectName': 'Advance Math',
- 'courseName': 'JCE',
+ 'courseId': 1234567890,
'logo_url': 'http://location.domain.com/image.jpg',
'gitRepository': 'http://location.git.com/somthing'
}
@@ -62,18 +62,14 @@ def create_project(token): payload = json.loads(request.data) except Exception as e: return bad_request("invalid JSON format") - #if not is_lecturer(token): #todo: change to lecturer id - # return forbidden("Invalid token or not a lecturer!") user = get_user_by_token(token) if user is None: return bad_request("Wrong user Token") - #todo: check legality - try: - project = Project(projectName=payload['projectName'], courseName=payload['courseName'], master_id=user.key().id(), gitRepository=payload['gitRepository'], membersId=[token]) + project = Project(projectName=payload['projectName'], courseId=payload['courseId'], master_id=user.key().id(), gitRepository=payload['gitRepository'], membersId=[token]) except Exception as e: print e return bad_request() @@ -142,14 +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(name): +def getProjectsByCourse(courseId): """ >This Call will return an array of all projects in a given course
Route Parameters
- - name: 'course name' + - courseId: 1234567890

Payload
@@ -162,7 +158,7 @@ def getProjectsByCourse(name): {
'projectName': 'Advance Math',
- 'courseName': 'JCE',
+ 'courseId': 123456789,
'grade': 98,
'logo_url': 'http://location.domain.com/image.jpg',
'gitRepository': 'http://location.git.com/somthing',
@@ -175,7 +171,7 @@ def getProjectsByCourse(name): arr = [] query = Project.all() - query.filter("courseName = ", name) + query.filter("courseId = ", int(courseId)) for p in query.run(): arr.append(dict(json.loads(p.to_JSON()))) diff --git a/models/Course.py b/models/Course.py index a96503a..444ed04 100644 --- a/models/Course.py +++ b/models/Course.py @@ -5,7 +5,7 @@ from google.appengine.ext import db class Course(db.Model): courseName = db.StringProperty(required=True) - campusName = db.StringProperty(required=True) + campusId = db.IntegerProperty(required=True) master_id = db.IntegerProperty(required=True) # projects = db.StringListProperty(required=True,default=[]) startDate = db.DateProperty(required=True) @@ -14,7 +14,7 @@ class Course(db.Model): def to_JSON(self): data = {'courseName' : self.courseName, - 'campusName' : self.campusName, + 'campusId' : self.campusName, 'master_id' : self.master_id, # 'projects' : self.projects, 'startDate' : { diff --git a/models/Project.py b/models/Project.py index 4e6cacb..042c082 100644 --- a/models/Project.py +++ b/models/Project.py @@ -5,7 +5,7 @@ from google.appengine.ext import db class Project(db.Model): projectName = db.StringProperty(required=True) - courseName = db.StringProperty(required=True) + courseId = db.IntegerProperty(required=True) master_id = db.IntegerProperty(required=True) grade = db.IntegerProperty(required=True, default=0) logo_url = db.StringProperty(required=False) @@ -14,7 +14,7 @@ class Project(db.Model): def to_JSON(self): data = {'projectName' : self.projectName, - 'courseName' : self.courseName, + 'courseId' : self.courseId, 'master_id' : self.master_id, 'grade' : self.grade, 'logo_url' : self.logo_url,