From e9e10bd980c9ea194fcf24d991e63cff92528332 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 22 Jun 2015 01:26:23 +0300 Subject: [PATCH] added delete functions + doc to campus, course, project --- SE_API/CampusRoutes.py | 32 +++++++++++----------------- SE_API/CourseRoutes.py | 38 ++++++++++++++++----------------- SE_API/ProjectRoutes.py | 47 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 40 deletions(-) diff --git a/SE_API/CampusRoutes.py b/SE_API/CampusRoutes.py index e6a2781..66a262a 100644 --- a/SE_API/CampusRoutes.py +++ b/SE_API/CampusRoutes.py @@ -140,15 +140,16 @@ def get_campuses(token): return forbidden("Invalid Token") -@campus_routes.route('/api/campuses/deleteCampus//', methods=['DELETE']) + +@campus_routes.route('/api/campuses/deleteCampus//', methods=['DELETE']) @auto.doc() -def deleteCampus(token,campusName): +def deleteCampus(token,campusid): """ This Call will delete a specific campus
Route Parameters
- seToken: 'seToken' - - title: 'campusName' + - campusid: 'campusid'

Payload
@@ -159,42 +160,33 @@ def deleteCampus(token,campusName):
202 - Deleted campus
- 204 - No Matching Campus Found -
....
{
...
}req
]
- 400 - Bad Request + 400 - no such campus
- 403 - Invalid token or not a lecturer!
+ 403 - Invalid token or not a lecturer or lecturer is not owner of campus!
""" if not is_lecturer(token): #todo: change to lecturer id return forbidden("Invalid token or not a lecturer!") - user = get_user_by_token(token) - query = Campus.all() - query.filter('master_user_id =',user.key().id()) + camp = Campus.get_by_id(int(campusid)) - try: - query.filter('title =', campusName) - except Exception as e: - print e - return bad_request("invalid campus title attribute") + if camp is None: + return bad_request("no such campus") - for c in query.run(): - db.delete(c) + if camp.master_user_id == user.key().id(): + db.delete(camp) db.save return accepted("campus deleted") - - return bad_request("no such campus found") - + return forbidden("lecturer is not owner of campus") diff --git a/SE_API/CourseRoutes.py b/SE_API/CourseRoutes.py index 93c2db6..fe27f61 100644 --- a/SE_API/CourseRoutes.py +++ b/SE_API/CourseRoutes.py @@ -272,15 +272,21 @@ def getMessagesByCourseName(name): #---------------------------------------------------------- # DELETE #---------------------------------------------------------- -@course_routes.route('/api/courses/deleteCourse//', methods=['DELETE']) + + + + + + +@course_routes.route('/api/courses/deleteCourse//', methods=['DELETE']) @auto.doc() -def deleteCourse(token,courseName): +def deleteCourse(token,courseid): """ - This Call will delete a specific course + This Call will delete a specific Course
Route Parameters
- seToken: 'seToken' - - title: 'courseName' + - courseid: 'courseid'

Payload
@@ -289,9 +295,7 @@ def deleteCourse(token,courseName):
Response
- 202 - Deleted campus -
- 204 - No Matching Campus Found + 202 - Deleted Course
....
{
@@ -299,33 +303,27 @@ def deleteCourse(token,courseName): }req
]
- 400 - Bad Request + 400 - no such Course
- 403 - Invalid token or not a lecturer!
+ 403 - Invalid token or not a lecturer or lecturer is not owner of Course!
""" if not is_lecturer(token): #todo: change to lecturer id return forbidden("Invalid token or not a lecturer!") - user = get_user_by_token(token) - query = Course.all() - query.filter('master_id =',user.key().id()) + c = Course.get_by_id(int(courseid)) - try: - query.filter('courseName =', courseName) - except Exception as e: - print e - return bad_request("invalid course title attribute") + if c is None: + return bad_request("no such course") - for c in query.run(): + if c.master_id == user.key().id(): db.delete(c) db.save return accepted("course deleted") - - return bad_request("no such course or not owner of course") + return forbidden("lecturer is not owner of course") @course_routes.route('/api/courses/deleteCoursesByCampus//', methods=['DELETE']) diff --git a/SE_API/ProjectRoutes.py b/SE_API/ProjectRoutes.py index 57afe8d..1bd3c23 100644 --- a/SE_API/ProjectRoutes.py +++ b/SE_API/ProjectRoutes.py @@ -130,6 +130,53 @@ def getProjectsByCourseName(name): +@project_routes.route('/api/projects/deleteProject//', methods=['DELETE']) +@auto.doc() +def deleteProject(token,projectid): + """ + This Call will delete a specific Project +
+ Route Parameters
+ - seToken: 'seToken' + - courseid: 'projectid' +
+
+ Payload
+ - NONE
+
+
+ Response +
+ 202 - Deleted Project +
+ ....
+ {
+ ...
+ }req
+ + ]
+ 400 - no such Project +
+ 403 - Invalid token or not the owner of Project!
+ """ + + # if not is_lecturer(token): #todo: change to lecturer id + # return forbidden("Invalid token or not a lecturer!") + + user = get_user_by_token(token) + p = Project.get_by_id(int(projectid)) + + if p is None: + return bad_request("no such Project") + + if p.master_id == user.key().id(): + db.delete(p) + db.save + return accepted("Project deleted") + + return forbidden("user is not owner of Project") + + @project_routes.route('/api/projects/help') def documentation():