diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index a7ec923..e9f2363 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -218,9 +218,9 @@ def getAllTasksByCourse(token, courseId): return no_content() -@task_routes.route('/api/tasks/getAllFutureTasks//', methods=["GET"]) +@task_routes.route('/api/tasks/getAllFutureCampusTasks//', methods=["GET"]) @auto.doc() -def getAllFutureTasks(token, courseId): +def getAllFutureCampusTasks(token, courseId): """ >This Call will return an array of all Future Tasks in a course, ordered by date
@@ -284,6 +284,73 @@ def getAllFutureTasks(token, courseId): else: return no_content() +@task_routes.route('/api/tasks/getAllFutureTasks/', methods=["GET"]) +@auto.doc() +def getAllFutureCampusTasks(token): + """ + >This Call will return an array of all Future Tasks ordered by date +
+ Route Parameters
+ - SeToken: token
+
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ + {
+ 'title' : 'Task1',
+ 'courseName' : 'advance Math',
+ 'description' : 'prepare by sunday',
+ 'dueDate' : { + 'year' : 2015, + 'month' : 12, + 'day' : 23 + }
+ 'isPersonal' : true,
+ 'task_id' : 589689456894
+ }
+
+
+ """ + + user = get_user_by_token + if user is None: + return bad_request("Bad User Token") + + arr = [] + + for courseId in user.courses_id_list: + query = Task.all() + + try: + query.filter("courseId = ", int(courseId)) + except Exception as e: + return bad_request("Bad id format") + + 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']) + if taskTime >= datetime.date.today(): + taskDic['forSortDate'] = taskTime + arr.append(taskDic) + + #sort array by date, and remove added key + arr = sorted(arr, key=itemgetter('forSortDate'), reverse=False) + for i in arr: + del i['forSortDate'] + + if len(arr) != 0: + return Response(response=json.dumps(arr), + status=200, + mimetype="application/json") + else: + return no_content() @task_routes.route('/api/tasks/getTaskComponents//', methods=["GET"])