From 41b62be4eccaa4cf5cb274620889746b9c52e4ec Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Tue, 23 Jun 2015 00:28:29 +0300 Subject: [PATCH] added deleteTask and deleteTaskComponents functions --- SE_API/TaskRoutes.py | 101 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index 5f163dd..ad3b990 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -321,6 +321,107 @@ def getTaskComponents(taskId): +@task_routes.route('/api/tasks/deleteTask//', methods=['DELETE']) +@auto.doc() +def deleteTask(token,taskid): + """ + This Call will delete a specific Task +
+ Route Parameters
+ - seToken: 'seToken' + - taskid: 'taskid' +
+
+ Payload
+ - NONE
+
+
+ Response +
+ 202 - Deleted Course +
+ ....
+ {
+ ...
+ }req
+ + ]
+ 400 - no such Course +
+ 403 - Invalid token or not a lecturer or lecturer is not owner of Course!
+ """ + + if not is_lecturer(token): + return forbidden("Invalid token or not a lecturer!") + + #todo: check if lecturer is owner of course + #return forbidden("lecturer is not owner of course") + + user = get_user_by_token(token) + c = Task.get_by_id(int(taskid)) + + if c is None: + return bad_request("no such Task") + + + db.delete(c) + db.save + return accepted("Task deleted") + + +@task_routes.route('/api/tasks/deleteTaskComponents//', methods=['DELETE']) +@auto.doc() +def deleteTaskComponents(token,taskid): + """ + This Call will delete a specific Task's components +
+ Route Parameters
+ - seToken: 'seToken' + - taskid: 'taskid' +
+
+ Payload
+ - NONE
+
+
+ Response +
+ 202 - Deleted Course +
+ ....
+ {
+ ...
+ }req
+ + ]
+ 400 - no such Task +
+ 403 - Invalid token or not a lecturer or lecturer is not owner of Task!
+ """ + + if not is_lecturer(token): + return forbidden("Invalid token or not a lecturer!") + + #todo: check if lecturer is owner of course + #return forbidden("lecturer is not owner of course") + + user = get_user_by_token(token) + t = Task.get_by_id(int(taskid)) + + if t is None: + return bad_request("no such Task") + + query = TaskComponent.all() + query.filter('taskId = ', t.key().id()) + + for tc in query.run(): + db.delete(tc) + + db.save + return accepted("Task deleted") + + + @task_routes.route('/api/tasks/help') def documentation(): return auto.html()