Merge pull request #86 from sagidayan/API_Dev

Api dev
This commit is contained in:
Sagi Dayan 2015-06-29 13:55:01 +03:00
commit 5b87b0a4d0
5 changed files with 35 additions and 31 deletions

View file

@ -231,7 +231,7 @@ def getProjectsByUser(token):
arr = [] arr = []
for p in user['projects_id_list']: for p in user.projects_id_list:
project = Project.get_by_id(int(p)) project = Project.get_by_id(int(p))
arr.append(dict(json.loads(project.to_JSON()))) arr.append(dict(json.loads(project.to_JSON())))

View file

@ -153,14 +153,15 @@ def create_task(token):
#---------------------------------------------------------- #----------------------------------------------------------
@task_routes.route('/api/tasks/getAllTasks/<string:courseName>', methods=["GET"]) @task_routes.route('/api/tasks/getAllTasksByCourse/<string:token>/<string:courseId>', methods=["GET"])
@auto.doc() @auto.doc()
def getAllTasks(courseName): def getAllTasksByCourse(token, courseId):
""" """
<span class="card-title">>This Call will return an array of all Tasks in a course by date</span> <span class="card-title">>This Call will return an array of all Tasks in a course ordered by date</span>
<br> <br>
<b>Route Parameters</b><br> <b>Route Parameters</b><br>
- name: 'course name' - SeToken: token<br>
- courseId: 1234567890
<br> <br>
<br> <br>
<b>Payload</b><br> <b>Payload</b><br>
@ -173,7 +174,7 @@ def getAllTasks(courseName):
<code> <code>
{<br> {<br>
'title' : 'Task1',<br> 'title' : 'Task1',<br>
'courseName' : 'advance Math',<br> 'courseId' : 12345678,<br>
'description' : 'prepare by sunday',<br> 'description' : 'prepare by sunday',<br>
'dueDate' : { 'dueDate' : {
'year' : 2015, 'year' : 2015,
@ -186,10 +187,12 @@ def getAllTasks(courseName):
</code> </code>
<br> <br>
""" """
if get_user_by_token(token) is None:
return bad_request("Bad User Token")
arr = [] arr = []
query = Task.all() query = Task.all()
query.filter("courseName = ", courseName) query.filter("courseId = ", courseId)
for t in query.run(): for t in query.run():
taskDic =dict(json.loads(t.to_JSON())) taskDic =dict(json.loads(t.to_JSON()))
@ -211,14 +214,15 @@ def getAllTasks(courseName):
return no_content() return no_content()
@task_routes.route('/api/tasks/getAllFutureTasks/<string:courseName>', methods=["GET"]) @task_routes.route('/api/tasks/getAllFutureTasks/<string:token>/<string:courseId>', methods=["GET"])
@auto.doc() @auto.doc()
def getAllFutureTasks(courseName): def getAllFutureTasks(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>
<b>Route Parameters</b><br> <b>Route Parameters</b><br>
- name: 'course name' - SeToken: token<br>
- courseId: 1234567890
<br> <br>
<br> <br>
<b>Payload</b><br> <b>Payload</b><br>
@ -245,9 +249,12 @@ def getAllFutureTasks(courseName):
<br> <br>
""" """
if get_user_by_token(token) is None:
return bad_request("Bad User Token")
arr = [] arr = []
query = Task.all() query = Task.all()
query.filter("courseName = ", courseName) query.filter("courseId = ", courseId)
for t in query.run(): for t in query.run():
taskDic =dict(json.loads(t.to_JSON())) taskDic =dict(json.loads(t.to_JSON()))
@ -271,14 +278,15 @@ def getAllFutureTasks(courseName):
@task_routes.route('/api/tasks/getTaskComponents/<string:taskId>', methods=["GET"]) @task_routes.route('/api/tasks/getTaskComponents/<string:token>/<string:taskId>', methods=["GET"])
@auto.doc() @auto.doc()
def getTaskComponents(taskId): def getTaskComponents(token, taskId):
""" """
<span class="card-title">>This Call will return an array of all components for a given task</span> <span class="card-title">>This Call will return an array of all components for a given task</span>
<br> <br>
<b>Route Parameters</b><br> <b>Route Parameters</b><br>
- taskId: integer - SeToken: token<br>
- taskId: 1234567890
<br> <br>
<br> <br>
<b>Payload</b><br> <b>Payload</b><br>
@ -311,6 +319,9 @@ def getTaskComponents(taskId):
<br> <br>
""" """
if get_user_by_token(token) is None:
return bad_request("Bad User Token")
arr = [] arr = []
query = TaskComponent.all() query = TaskComponent.all()
query.filter("taskId = ", taskId) query.filter("taskId = ", taskId)
@ -336,15 +347,15 @@ def getTaskComponents(taskId):
@task_routes.route('/api/tasks/deleteTask/<string:token>/<string:taskid>', methods=['DELETE']) @task_routes.route('/api/tasks/deleteTask/<string:token>/<string:taskId>', methods=['DELETE'])
@auto.doc() @auto.doc()
def deleteTask(token,taskid): def deleteTask(token, taskId):
""" """
<span class="card-title">This Call will delete a specific Task</span> <span class="card-title">This Call will delete a specific Task</span>
<br> <br>
<b>Route Parameters</b><br> <b>Route Parameters</b><br>
- seToken: 'seToken' - seToken: 'seToken'
- taskid: 'taskid' - taskId: 'taskid'
<br> <br>
<br> <br>
<b>Payload</b><br> <b>Payload</b><br>
@ -373,7 +384,7 @@ def deleteTask(token,taskid):
#return forbidden("lecturer is not owner of course") #return forbidden("lecturer is not owner of course")
user = get_user_by_token(token) user = get_user_by_token(token)
c = Task.get_by_id(int(taskid)) c = Task.get_by_id(int(taskId))
if c is None: if c is None:
return bad_request("no such Task") return bad_request("no such Task")
@ -384,15 +395,15 @@ def deleteTask(token,taskid):
return accepted("Task deleted") return accepted("Task deleted")
@task_routes.route('/api/tasks/deleteTaskComponents/<string:token>/<string:taskid>', methods=['DELETE']) @task_routes.route('/api/tasks/deleteTaskComponents/<string:token>/<string:taskId>', methods=['DELETE'])
@auto.doc() @auto.doc()
def deleteTaskComponents(token,taskid): def deleteTaskComponents(token,taskId):
""" """
<span class="card-title">This Call will delete a specific Task's components</span> <span class="card-title">This Call will delete a specific Task's components</span>
<br> <br>
<b>Route Parameters</b><br> <b>Route Parameters</b><br>
- seToken: 'seToken' - seToken: 'seToken'
- taskid: 'taskid' - taskId: 'taskid'
<br> <br>
<br> <br>
<b>Payload</b><br> <b>Payload</b><br>
@ -421,7 +432,7 @@ def deleteTaskComponents(token,taskid):
#return forbidden("lecturer is not owner of course") #return forbidden("lecturer is not owner of course")
user = get_user_by_token(token) user = get_user_by_token(token)
t = Task.get_by_id(int(taskid)) t = Task.get_by_id(int(taskId))
if t is None: if t is None:
return bad_request("no such Task") return bad_request("no such Task")

View file

@ -53,7 +53,6 @@ def updateUser(token):
{<br> {<br>
'name': 'new name',<br> 'name': 'new name',<br>
'isLecturer': true,<br> 'isLecturer': true,<br>
'campusName': 'JCE'<br>
}<br> }<br>
<br> <br>
<b>Response</b> <b>Response</b>
@ -80,10 +79,6 @@ def updateUser(token):
except Exception: except Exception:
pass pass
try:
user.campusName = payload['campusName']
except Exception:
pass
try: try:
user.isLecturer = payload['isLecturer'] user.isLecturer = payload['isLecturer']

View file

@ -6,14 +6,14 @@ from google.appengine.ext import db
class Task(db.Model): class Task(db.Model):
title = db.StringProperty(required=True) title = db.StringProperty(required=True)
courseName = db.StringProperty(required=True) courseId = db.IntegerProperty(required=True)
description = db.StringProperty(required=True,default=" ") description = db.StringProperty(required=True,default=" ")
dueDate = db.DateProperty(required=True) dueDate = db.DateProperty(required=True)
isPersonal = db.BooleanProperty(required=True, default=True) isPersonal = db.BooleanProperty(required=True, default=True)
def to_JSON(self): def to_JSON(self):
data = {'title' : self.title, data = {'title' : self.title,
'courseName' : self.courseName, 'courseId' : self.courseId,
'description' : self.description, 'description' : self.description,
'dueDate' : { 'dueDate' : {
'year': self.dueDate.year, 'year': self.dueDate.year,

View file

@ -12,7 +12,6 @@ class User(db.Model):
seToken = db.StringProperty(required=True) seToken = db.StringProperty(required=True)
avatar_url = db.StringProperty(required=True) avatar_url = db.StringProperty(required=True)
isFirstLogin = db.BooleanProperty(default=True) isFirstLogin = db.BooleanProperty(default=True)
campusName = db.StringProperty(required=True, default=" ")
campuses_id_list = db.StringListProperty(default=[]) campuses_id_list = db.StringListProperty(default=[])
courses_id_list = db.StringListProperty(default=[]) courses_id_list = db.StringListProperty(default=[])
projects_id_list = db.StringListProperty(default=[]) projects_id_list = db.StringListProperty(default=[])
@ -24,7 +23,6 @@ class User(db.Model):
'isLecturer' : self.isLecturer, 'isLecturer' : self.isLecturer,
'avatar_url' : self.avatar_url, 'avatar_url' : self.avatar_url,
'isFirstLogin' : self.isFirstLogin, 'isFirstLogin' : self.isFirstLogin,
'campusName': self.campusName,
'campuses_id_list': self.campuses_id_list, 'campuses_id_list': self.campuses_id_list,
'courses_id_list': self.courses_id_list, 'courses_id_list': self.courses_id_list,
'projects_id_list': self.projects_id_list, 'projects_id_list': self.projects_id_list,