Task Rework - chaged parameters
added components module and creation in create task added getTaskComponents function
This commit is contained in:
parent
7729b3d884
commit
cd0fb3cf4f
3 changed files with 190 additions and 114 deletions
|
@ -18,6 +18,7 @@ from flask.ext.autodoc import Autodoc
|
|||
# DB Models
|
||||
from models.Task import Task
|
||||
from models.Course import Course
|
||||
from models.TaskComponent import TaskComponent
|
||||
|
||||
#Validation Utils Libs
|
||||
from SE_API.Validation_Utils import *
|
||||
|
@ -42,14 +43,35 @@ def create_task(token):
|
|||
<b>Payload</b><br>
|
||||
- JSON Object, Example: <br>
|
||||
{<br>
|
||||
'title' : self.title,<br>
|
||||
'courseName' : self.course,<br>
|
||||
'description' : self.description,<br>
|
||||
'dueDate' : self.dueDate,<br>
|
||||
'isClose' : self.membersId,<br>
|
||||
'isDone' : self.isDone,<br>
|
||||
'taskGrade' : self.taskGrade<br>
|
||||
}<br>
|
||||
"title":"task1",<br>
|
||||
"courseName":"aran",<br>
|
||||
"description":"pls fddfsdfdsk",<br>
|
||||
"dueDate":{"year":2010,<br>
|
||||
"month":2,<br>
|
||||
"day":4<br>
|
||||
},
|
||||
"isPersonal":true,<br>
|
||||
"components":[<br>
|
||||
{<br>
|
||||
"type" : "should be type1",<br>
|
||||
"label" : "should be label1",<br>
|
||||
"isMandatory" : true,<br>
|
||||
"order" : 1<br>
|
||||
},<br>
|
||||
{<br>
|
||||
"type" : "should be type2",<br>
|
||||
"label" : "should be label2",<br>
|
||||
"isMandatory" : true,<br>
|
||||
"order" : 2<br>
|
||||
},<br>
|
||||
{<br>
|
||||
"type" : "should be type3",<br>
|
||||
"label" : "should be label3",<br>
|
||||
"isMandatory" : false,<br>
|
||||
"order" : 3<br>
|
||||
}<br>
|
||||
]<br>
|
||||
}
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
|
@ -90,89 +112,37 @@ def create_task(token):
|
|||
date = datetime.date(payload['dueDate']['year'],payload['dueDate']['month'],payload['dueDate']['day'])
|
||||
except Exception:
|
||||
return bad_request("invalid dueDate format")
|
||||
#TODO: add time. now, its only date
|
||||
|
||||
task = Task(title=payload['title'], courseName=payload['courseName'], description=payload['description'], dueDate=date)
|
||||
|
||||
#parse isClose
|
||||
# print "id: ",task.key().id()
|
||||
#parse isPersonal
|
||||
try:
|
||||
task.isClose = payload['isClose']
|
||||
task.isPersonal = payload['isPersonal']
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
#parse isDone
|
||||
try:
|
||||
task.isDone = payload['isDone']
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
#parse taskGrade
|
||||
try:
|
||||
task.taskGrade = payload['taskGrade']
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
except Exception as e:
|
||||
print e
|
||||
return bad_request()
|
||||
|
||||
db.put(task)
|
||||
db.save
|
||||
|
||||
#create components
|
||||
for c in payload['components']:
|
||||
try:
|
||||
component = TaskComponent(taskId=task.key().id(), userId=-1, 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 created()
|
||||
|
||||
|
||||
|
||||
@task_routes.route('/api/tasks/getClosestTask/<string:courseName>', methods=["GET"])
|
||||
@auto.doc()
|
||||
def getClosestTask(courseName):
|
||||
"""
|
||||
<span class="card-title">>This Call will return an array of all projects in a given course</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- name: 'course name'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
200 - JSON Example:<br>
|
||||
<code>
|
||||
{<br>
|
||||
'projectName': 'Advance Math',<br>
|
||||
'courseName': 'JCE',<br>
|
||||
'grade': 98,<br>
|
||||
'logo_url': 'http://location.domain.com/image.jpg',<br>
|
||||
'gitRepository': 'http://location.git.com/somthing',<br>
|
||||
'membersId': ['bob', 'dylan', 'quentin', 'terentino']<br>
|
||||
}
|
||||
</code>
|
||||
<br>
|
||||
"""
|
||||
#get all tasks for a specific course
|
||||
arr = []
|
||||
query = Task.all()
|
||||
query.filter("courseName =", courseName)
|
||||
index = -1
|
||||
count = -1
|
||||
closestDate = datetime.date(3000,1,1)
|
||||
for t in query.run():
|
||||
count+=1
|
||||
if t.dueDate < closestDate:
|
||||
closestDate = t.dueDate
|
||||
index = count
|
||||
arr.append(dict(json.loads(t.to_JSON())))
|
||||
|
||||
print arr
|
||||
if len(arr) != 0:
|
||||
return Response(response=json.dumps(arr[index]),
|
||||
status=200,
|
||||
mimetype="application/json")
|
||||
else:
|
||||
return no_content("no Tasks")
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -180,7 +150,7 @@ def getClosestTask(courseName):
|
|||
@auto.doc()
|
||||
def getAllTasks(courseName):
|
||||
"""
|
||||
<span class="card-title">>This Call will return an array of all projects in a given course</span>
|
||||
<span class="card-title">>This Call will return an array of all Tasks in a course by date</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- name: 'course name'
|
||||
|
@ -195,13 +165,17 @@ def getAllTasks(courseName):
|
|||
200 - JSON Example:<br>
|
||||
<code>
|
||||
{<br>
|
||||
'projectName': 'Advance Math',<br>
|
||||
'courseName': 'JCE',<br>
|
||||
'grade': 98,<br>
|
||||
'logo_url': 'http://location.domain.com/image.jpg',<br>
|
||||
'gitRepository': 'http://location.git.com/somthing',<br>
|
||||
'membersId': ['bob', 'dylan', 'quentin', 'terentino']<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>
|
||||
"""
|
||||
|
@ -227,12 +201,128 @@ def getAllTasks(courseName):
|
|||
status=200,
|
||||
mimetype="application/json")
|
||||
else:
|
||||
return Response(response=[],
|
||||
return no_content()
|
||||
|
||||
|
||||
@task_routes.route('/api/tasks/getTaskComponents/<string:taskId>', methods=["GET"])
|
||||
@auto.doc()
|
||||
def getTaskComponents(taskId):
|
||||
"""
|
||||
<span class="card-title">>This Call will return an array of all components for a given task</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- taskId: integer
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
200 - JSON Example:<br>
|
||||
<code>
|
||||
[
|
||||
{<br>
|
||||
'taskId' : 7589454894,
|
||||
'userId' : -1,
|
||||
'type' : 'kindOfType',
|
||||
'label' : 'kindOfLabel',
|
||||
'isMandatory' : true,
|
||||
'order' : 2
|
||||
}<br>
|
||||
{<br>
|
||||
'taskId' : 7589454894,
|
||||
'userId' : yossi,
|
||||
'type' : 'otherKindOfType',
|
||||
'label' : 'otherKindOfLabel',
|
||||
'isMandatory' : false,
|
||||
'order' : 4
|
||||
}<br>
|
||||
]
|
||||
</code>
|
||||
<br>
|
||||
"""
|
||||
|
||||
arr = []
|
||||
query = TaskComponent.all()
|
||||
query.filter("taskId = ", taskId)
|
||||
|
||||
for tc in query.run():
|
||||
arr.append(dict(json.loads(tc.to_JSON())))
|
||||
|
||||
#sort array by order, and remove added key
|
||||
arr = sorted(arr, key=itemgetter('order'), reverse=False)
|
||||
|
||||
if len(arr) != 0:
|
||||
return Response(response=json.dumps(arr),
|
||||
status=200,
|
||||
mimetype="application/json")
|
||||
else:
|
||||
return no_content()
|
||||
|
||||
|
||||
|
||||
@task_routes.route('/api/tasks/help')
|
||||
def documentation():
|
||||
return auto.html()
|
||||
|
||||
|
||||
|
||||
@task_routes.route('/api/tasks/help')
|
||||
def documentation():
|
||||
return auto.html()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# @task_routes.route('/api/tasks/getClosestTask/<string:courseName>', methods=["GET"])
|
||||
# @auto.doc()
|
||||
# def getClosestTask(courseName):
|
||||
# """
|
||||
# <span class="card-title">>This Call will return an array of all projects in a given course</span>
|
||||
# <br>
|
||||
# <b>Route Parameters</b><br>
|
||||
# - name: 'course name'
|
||||
# <br>
|
||||
# <br>
|
||||
# <b>Payload</b><br>
|
||||
# - NONE
|
||||
# <br>
|
||||
# <br>
|
||||
# <b>Response</b>
|
||||
# <br>
|
||||
# 200 - JSON Example:<br>
|
||||
# <code>
|
||||
# {<br>
|
||||
# 'projectName': 'Advance Math',<br>
|
||||
# 'courseName': 'JCE',<br>
|
||||
# 'grade': 98,<br>
|
||||
# 'logo_url': 'http://location.domain.com/image.jpg',<br>
|
||||
# 'gitRepository': 'http://location.git.com/somthing',<br>
|
||||
# 'membersId': ['bob', 'dylan', 'quentin', 'terentino']<br>
|
||||
# }
|
||||
# </code>
|
||||
# <br>
|
||||
# """
|
||||
# #get all tasks for a specific course
|
||||
# arr = []
|
||||
# query = Task.all()
|
||||
# query.filter("courseName =", courseName)
|
||||
# for t in query.run():
|
||||
# count+=1
|
||||
# if t.dueDate < closestDate:
|
||||
# closestDate = t.dueDate
|
||||
# index = count
|
||||
# arr.append(dict(json.loads(t.to_JSON())))
|
||||
#
|
||||
# print arr
|
||||
# if len(arr) != 0:
|
||||
# return Response(response=json.dumps(arr[index]),
|
||||
# status=200,
|
||||
# mimetype="application/json")
|
||||
# else:
|
||||
# return no_content("no Tasks")
|
||||
#
|
||||
|
|
|
@ -9,10 +9,7 @@ class Task(db.Model):
|
|||
courseName = db.StringProperty(required=True)
|
||||
description = db.StringProperty(required=True,default=" ")
|
||||
dueDate = db.DateProperty(required=True)
|
||||
#isProject = db.BooleanProperty(required=False)
|
||||
isClose = db.BooleanProperty(required=True, default=False)
|
||||
isDone = db.BooleanProperty(required=True, default=False)
|
||||
taskGrade = db.IntegerProperty(required=True, default=0)
|
||||
isPersonal = db.BooleanProperty(required=True, default=True)
|
||||
|
||||
def to_JSON(self):
|
||||
data = {'title' : self.title,
|
||||
|
@ -23,10 +20,7 @@ class Task(db.Model):
|
|||
'month': self.dueDate.month,
|
||||
'day': self.dueDate.day
|
||||
},
|
||||
#'isProject' : self.isProject,
|
||||
'isClose' : self.isClose,
|
||||
'isDone' : self.isDone,
|
||||
'taskGrade' : self.taskGrade,
|
||||
'isPersonal' : self.isPersonal,
|
||||
}
|
||||
return json.dumps(data)
|
||||
|
||||
|
|
|
@ -6,27 +6,19 @@ from google.appengine.ext import db
|
|||
|
||||
|
||||
class TaskComponent(db.Model):
|
||||
taskId = db.StringProperty(required=True)
|
||||
courseName = db.StringProperty(required=True)
|
||||
description = db.StringProperty(required=True,default=" ")
|
||||
dueDate = db.DateProperty(required=True)
|
||||
#isProject = db.BooleanProperty(required=False)
|
||||
isClose = db.BooleanProperty(required=True, default=False)
|
||||
isDone = db.BooleanProperty(required=True, default=False)
|
||||
taskGrade = db.IntegerProperty(required=True, default=0)
|
||||
taskId = db.IntegerProperty(required=True)
|
||||
userId = db.IntegerProperty(required=True, default = -1)
|
||||
type = db.StringProperty(required=True,default=" ")
|
||||
label = db.StringProperty(required=True,default=" ")
|
||||
isMandatory = db.BooleanProperty(required=True, default=True)
|
||||
order = db.IntegerProperty(required=True)
|
||||
|
||||
def to_JSON(self):
|
||||
data = {'title' : self.title,
|
||||
'courseName' : self.courseName,
|
||||
'description' : self.description,
|
||||
'dueDate' : {
|
||||
'year': self.dueDate.year,
|
||||
'month': self.dueDate.month,
|
||||
'day': self.dueDate.day
|
||||
},
|
||||
#'isProject' : self.isProject,
|
||||
'isClose' : self.isClose,
|
||||
'isDone' : self.isDone,
|
||||
'taskGrade' : self.taskGrade,
|
||||
data = {'taskId' : self.taskId,
|
||||
'userId' : self.userId,
|
||||
'type' : self.type,
|
||||
'label' : self.label,
|
||||
'isMandatory' : self.isMandatory,
|
||||
'order' : self.order
|
||||
}
|
||||
return json.dumps(data)
|
||||
|
|
Loading…
Reference in a new issue