diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index c587901..e4c0296 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -143,7 +143,79 @@ def create_task(token): status=200, mimetype="application/json") +@task_routes.route('/api/tasks/submitTask///', methods=['POST']) +@auto.doc() +def submitTask(token, taskId, ownerId): + """ + 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 + """ + if not request.data: + return bad_request("no payload") + payload = json.loads(request.data) + user = get_user_by_token(token) + + task = Task.get_by_id(int(taskId)) + + #create components + for c in payload['components']: + try: + component = TaskComponent(taskId=task.key().id(), userId=(int(ownerId)), type=c['type'], label=c['label'], isMandatory=c['isMandatory'], order=c['order']) + except Exception as e: + print e + return bad_request("Bad component") + db.put(component) + db.save + + return Response(response=task.to_JSON(), + status=200, + mimetype="application/json") #---------------------------------------------------------- # PUT #---------------------------------------------------------- @@ -267,7 +339,7 @@ def getAllFutureCampusTasks(token, courseId): for t in query.run(): taskDic =dict(json.loads(t.to_JSON())) #add a key 'forSortDate' for sorting dates - taskTime = datetime.datetime(taskDic['dueDate']['year'], taskDic['dueDate']['month'], taskDic['dueDate']['day']) + taskTime = datetime.date(taskDic['dueDate']['year'], taskDic['dueDate']['month'], taskDic['dueDate']['day']) if taskTime >= datetime.date.today(): taskDic['forSortDate'] = taskTime arr.append(taskDic) @@ -335,7 +407,7 @@ def getAllFutureTasks(token): for t in query.run(): taskDic =dict(json.loads(t.to_JSON())) #add a key 'forSortDate' for sorting dates - taskTime = datetime.datetime(taskDic['dueDate']['year'], taskDic['dueDate']['month'], taskDic['dueDate']['day']) + taskTime = datetime.date(taskDic['dueDate']['year'], taskDic['dueDate']['month'], taskDic['dueDate']['day']) if taskTime >= datetime.date.today(): taskDic['forSortDate'] = taskTime arr.append(taskDic) @@ -558,15 +630,16 @@ def getAllUserTasks(token): -@task_routes.route('/api/tasks/getUserTaskById//', methods=["GET"]) +@task_routes.route('/api/tasks/getTaskById///', methods=["GET"]) @auto.doc() -def getUserTaskById(token, taskId): +def getTaskById(token, taskId, ownerId): """ >This Call will return an array of all components for a given task
Route Parameters
- SeToken: token
- taskId: 1234567890 + - ownerId: 123456789

Payload
@@ -606,33 +679,45 @@ def getUserTaskById(token, taskId): if task is None: return bad_request("Bad Task id") + task = json.loads(task.to_JSON()) + task['components'] = [] + task['grade'] = {} taskCompQuery = TaskComponent.all() - taskCompQuery.filter("taskId = ", task.key().id()) + taskCompQuery.filter("taskId = ", taskId) - if task.isPersonal: - taskCompQuery.filter("userId = ", user.key().id()) - else: - taskCompQuery.filter("userId = ", user.key().id())#TODO: fix to project + taskCompQuery.filter("userId = ", ownerId) + # if task.isPersonal: + # taskCompQuery.filter("userId = ", user.key().id()) + # else: + # taskCompQuery.filter("userId = ", user.key().id())#TODO: fix to project #check if never created a personalized task and if so, create it if taskCompQuery.count() == 0: - taskCompQuery = TaskComponent.all().filter("taskId = ", task.key().id()).filter("userId = ", -1) - for tc in taskCompQuery.run(): - tcNew = TaskComponent(taskId=tc.taskId, userId=user.key().id(), type=tc.type, label=tc.label, isMandatory=tc.isMandatory, order=tc.order) - db.put(tcNew) + print "here" + taskCompQuery = TaskComponent.all().filter("taskId =", int(taskId)).filter("userId =", -1) + print "query count is: ", taskCompQuery.count() + for tc in taskCompQuery.run(): + task['components'].append(dict(json.loads(tc.to_JSON()))) - grade = TaskGrade(grade=0, taskId=task.key().id(), userId=user.key().id()) - db.put(grade) + # for tc in taskCompQuery.run(): + # tcNew = TaskComponent(taskId=tc.taskId, userId=user.key().id(), type=tc.type, label=tc.label, isMandatory=tc.isMandatory, order=tc.order) + # db.put(tcNew) + + # grade = TaskGrade(grade=0, taskId=task.key().id(), userId=user.key().id()) + # db.put(grade) + grade = TaskGrade.all().filter("taskId = ", taskId).filter("userId = ", ownerId) + gradeFound = False + for g in grade.run(): + task['grade'] = g + gradeFound = True + if not gradeFound: + task['grade'] = {'taskId': taskId, 'userId': ownerId, 'grade': None} - - - - - - db.save - return no_content() + return Response(response=json.dumps(task), + status=200, + mimetype="application/json")