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()