added getAllFutureTasks
This commit is contained in:
parent
448a9e66f7
commit
c826b06f02
1 changed files with 69 additions and 2 deletions
|
@ -218,9 +218,9 @@ def getAllTasksByCourse(token, courseId):
|
||||||
return no_content()
|
return no_content()
|
||||||
|
|
||||||
|
|
||||||
@task_routes.route('/api/tasks/getAllFutureTasks/<string:token>/<string:courseId>', methods=["GET"])
|
@task_routes.route('/api/tasks/getAllFutureCampusTasks/<string:token>/<string:courseId>', methods=["GET"])
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def getAllFutureTasks(token, courseId):
|
def getAllFutureCampusTasks(token, courseId):
|
||||||
"""
|
"""
|
||||||
<span class="card-title">>This Call will return an array of all Future Tasks in a course, ordered by date</span>
|
<span class="card-title">>This Call will return an array of all Future Tasks in a course, ordered by date</span>
|
||||||
<br>
|
<br>
|
||||||
|
@ -284,6 +284,73 @@ def getAllFutureTasks(token, courseId):
|
||||||
else:
|
else:
|
||||||
return no_content()
|
return no_content()
|
||||||
|
|
||||||
|
@task_routes.route('/api/tasks/getAllFutureTasks/<string:token>', methods=["GET"])
|
||||||
|
@auto.doc()
|
||||||
|
def getAllFutureCampusTasks(token):
|
||||||
|
"""
|
||||||
|
<span class="card-title">>This Call will return an array of all Future Tasks ordered by date</span>
|
||||||
|
<br>
|
||||||
|
<b>Route Parameters</b><br>
|
||||||
|
- SeToken: token<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<b>Payload</b><br>
|
||||||
|
- NONE
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<b>Response</b>
|
||||||
|
<br>
|
||||||
|
200 - JSON Example:<br>
|
||||||
|
<code>
|
||||||
|
{<br>
|
||||||
|
'title' : 'Task1',<br>
|
||||||
|
'courseName' : 'advance Math',<br>
|
||||||
|
'description' : 'prepare by sunday',<br>
|
||||||
|
'dueDate' : {
|
||||||
|
'year' : 2015,
|
||||||
|
'month' : 12,
|
||||||
|
'day' : 23
|
||||||
|
}<br>
|
||||||
|
'isPersonal' : true,<br>
|
||||||
|
'task_id' : 589689456894<br>
|
||||||
|
}<br>
|
||||||
|
</code>
|
||||||
|
<br>
|
||||||
|
"""
|
||||||
|
|
||||||
|
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/<string:token>/<string:taskId>', methods=["GET"])
|
@task_routes.route('/api/tasks/getTaskComponents/<string:token>/<string:taskId>', methods=["GET"])
|
||||||
|
|
Loading…
Reference in a new issue