From 0460d9b6662d7f85d2ce53889c110c16a609ef35 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Tue, 23 Jun 2015 00:10:39 +0300 Subject: [PATCH] added function: getAllFutureTasks --- SE_API/TaskRoutes.py | 62 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index 769e25b..5f163dd 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -137,8 +137,6 @@ def create_task(token): db.put(component) db.save - - return created() @@ -204,6 +202,66 @@ def getAllTasks(courseName): return no_content() +@task_routes.route('/api/tasks/getAllFutureTasks/', methods=["GET"]) +@auto.doc() +def getAllFutureTasks(courseName): + """ + >This Call will return an array of all Future Tasks in a course, ordered by date +
+ Route Parameters
+ - name: 'course name' +
+
+ 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
+ }
+
+
+ """ + + arr = [] + query = Task.all() + query.filter("courseName = ", courseName) + + 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"]) @auto.doc() def getTaskComponents(taskId):