diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index 302c94d..64e04a0 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -230,6 +230,95 @@ def submitTask(token, taskId, ownerId): return Response(response=task.to_JSON(), status=200, mimetype="application/json") + + +@task_routes.route('/api/tasks/submitGrade////', methods=['POST']) +@auto.doc() +def submitTask(token, taskId, ownerId, grade): + """ + This call will create a new Task in the DB +
+ Route Parameters
+ - seToken: 'seToken' +
+
+ Payload
+ - JSON Object, Example:
+ {
+ "title":"task1",
+ "courseId":1234567890,
+ "description":"pls fddfsdfdsk",
+ "dueDate":{"year":2010,
+ "month":2,
+ "day":4
+ }, + "isPersonal":true,
+ "components":[
+ {
+ "type" : "should be type1",
+ "label" : "should be label1",
+ "isMandatory" : true,
+ "order" : 1
+ },
+ {
+ "type" : "should be type2",
+ "label" : "should be label2",
+ "isMandatory" : true,
+ "order" : 2
+ },
+ {
+ "type" : "should be type3",
+ "label" : "should be label3",
+ "isMandatory" : false,
+ "order" : 3
+ }
+ ]
+} +
+
+ Response +
+ 201 - Created +
+ 400 - Bad Request +
+ 403 - Invalid token or not a lecturer + """ + user = get_user_by_token(token) + if user is None: + bad_request("bad user Token") + + task = Task.get_by_id(int(taskId)) + if task is None: + bad_request("bad Task id") + + + if task.isPersonal: + if User.get_by_id(int(ownerId)) is None: + return bad_request("no such user") + else: + if Project.get_by_id(int(ownerId)) is None: + return bad_request("no such project") + + try: + tg = TaskGrade.all().filter("taskId = ", int(taskId)).filter("userId = ", int(ownerId)) + if tg.count() == 0: + grade = TaskGrade(taskId=int(taskId), userId=int(ownerId), grade=int(grade)) + else: + for g in tg.run(): + g.grade=int(grade) + g.taskId=int(taskId) + g.userId=int(ownerId) + db.put(grade) + db.save + return Response(response=grade.to_JSON(), + status=200, + mimetype="application/json") + except Exception as e: + print e.message + return bad_request("wrong format") + + #---------------------------------------------------------- # PUT #----------------------------------------------------------