From 4794771b15a45892a32bd76840de03319225a87c Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 29 Jun 2015 13:40:11 +0300 Subject: [PATCH] updated task functions --- SE_API/TaskRoutes.py | 53 ++++++++++++++++++++++++++------------------ models/Task.py | 4 ++-- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index ab36b2e..136a2ab 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -153,14 +153,15 @@ def create_task(token): #---------------------------------------------------------- -@task_routes.route('/api/tasks/getAllTasks/', methods=["GET"]) +@task_routes.route('/api/tasks/getAllTasksByCourse//', methods=["GET"]) @auto.doc() -def getAllTasks(courseName): +def getAllTasksByCourse(token, courseId): """ - >This Call will return an array of all Tasks in a course by date + >This Call will return an array of all Tasks in a course ordered by date
Route Parameters
- - name: 'course name' + - SeToken: token
+ - courseId: 1234567890

Payload
@@ -173,7 +174,7 @@ def getAllTasks(courseName): {
'title' : 'Task1',
- 'courseName' : 'advance Math',
+ 'courseId' : 12345678,
'description' : 'prepare by sunday',
'dueDate' : { 'year' : 2015, @@ -186,10 +187,12 @@ def getAllTasks(courseName):

""" + if get_user_by_token(token) is None: + return bad_request("Bad User Token") arr = [] query = Task.all() - query.filter("courseName = ", courseName) + query.filter("courseId = ", courseId) for t in query.run(): taskDic =dict(json.loads(t.to_JSON())) @@ -211,14 +214,15 @@ def getAllTasks(courseName): return no_content() -@task_routes.route('/api/tasks/getAllFutureTasks/', methods=["GET"]) +@task_routes.route('/api/tasks/getAllFutureTasks//', methods=["GET"]) @auto.doc() -def getAllFutureTasks(courseName): +def getAllFutureTasks(token, courseId): """ >This Call will return an array of all Future Tasks in a course, ordered by date
Route Parameters
- - name: 'course name' + - SeToken: token
+ - courseId: 1234567890

Payload
@@ -245,9 +249,12 @@ def getAllFutureTasks(courseName):
""" + if get_user_by_token(token) is None: + return bad_request("Bad User Token") + arr = [] query = Task.all() - query.filter("courseName = ", courseName) + query.filter("courseId = ", courseId) for t in query.run(): taskDic =dict(json.loads(t.to_JSON())) @@ -271,14 +278,15 @@ def getAllFutureTasks(courseName): -@task_routes.route('/api/tasks/getTaskComponents/', methods=["GET"]) +@task_routes.route('/api/tasks/getTaskComponents//', methods=["GET"]) @auto.doc() -def getTaskComponents(taskId): +def getTaskComponents(token, taskId): """ >This Call will return an array of all components for a given task
Route Parameters
- - taskId: integer + - SeToken: token
+ - taskId: 1234567890

Payload
@@ -311,6 +319,9 @@ def getTaskComponents(taskId):
""" + if get_user_by_token(token) is None: + return bad_request("Bad User Token") + arr = [] query = TaskComponent.all() query.filter("taskId = ", taskId) @@ -336,15 +347,15 @@ def getTaskComponents(taskId): -@task_routes.route('/api/tasks/deleteTask//', methods=['DELETE']) +@task_routes.route('/api/tasks/deleteTask//', methods=['DELETE']) @auto.doc() -def deleteTask(token,taskid): +def deleteTask(token, taskId): """ This Call will delete a specific Task
Route Parameters
- seToken: 'seToken' - - taskid: 'taskid' + - taskId: 'taskid'

Payload
@@ -373,7 +384,7 @@ def deleteTask(token,taskid): #return forbidden("lecturer is not owner of course") user = get_user_by_token(token) - c = Task.get_by_id(int(taskid)) + c = Task.get_by_id(int(taskId)) if c is None: return bad_request("no such Task") @@ -384,15 +395,15 @@ def deleteTask(token,taskid): return accepted("Task deleted") -@task_routes.route('/api/tasks/deleteTaskComponents//', methods=['DELETE']) +@task_routes.route('/api/tasks/deleteTaskComponents//', methods=['DELETE']) @auto.doc() -def deleteTaskComponents(token,taskid): +def deleteTaskComponents(token,taskId): """ This Call will delete a specific Task's components
Route Parameters
- seToken: 'seToken' - - taskid: 'taskid' + - taskId: 'taskid'

Payload
@@ -421,7 +432,7 @@ def deleteTaskComponents(token,taskid): #return forbidden("lecturer is not owner of course") user = get_user_by_token(token) - t = Task.get_by_id(int(taskid)) + t = Task.get_by_id(int(taskId)) if t is None: return bad_request("no such Task") diff --git a/models/Task.py b/models/Task.py index cdbaae9..5449fa2 100644 --- a/models/Task.py +++ b/models/Task.py @@ -6,14 +6,14 @@ from google.appengine.ext import db class Task(db.Model): title = db.StringProperty(required=True) - courseName = db.StringProperty(required=True) + courseId = db.IntegerProperty(required=True) description = db.StringProperty(required=True,default=" ") dueDate = db.DateProperty(required=True) isPersonal = db.BooleanProperty(required=True, default=True) def to_JSON(self): data = {'title' : self.title, - 'courseName' : self.courseName, + 'courseId' : self.courseId, 'description' : self.description, 'dueDate' : { 'year': self.dueDate.year,