IMPORTANT: alot of function name changes and new Doc
This commit is contained in:
parent
664fcedca0
commit
1574b7e19e
4 changed files with 78 additions and 82 deletions
|
@ -49,7 +49,7 @@ def create_course(token):
|
|||
- JSON Object, Example: <br>
|
||||
{<br>
|
||||
'courseName': 'Advance Math',<br>
|
||||
'campusName': 'JCE',<br>
|
||||
'campusId': 1234567890,<br>
|
||||
'startDate': {'year': 2015, 'month' : 4, 'day' : 3},<br>
|
||||
'endDate': {'year': 2016, 'month' : 5, 'day' : 14}<br>
|
||||
}<br>
|
||||
|
@ -83,7 +83,7 @@ def create_course(token):
|
|||
if end_date <= start_date:
|
||||
return bad_request("end date cant be before (or same day) start date")
|
||||
|
||||
course = Course(courseName=payload['courseName'], campusName=payload['campusName'], master_id=user.key().id(),
|
||||
course = Course(courseName=payload['courseName'], campusId=payload['campusId'], master_id=user.key().id(),
|
||||
startDate=start_date, endDate=end_date)
|
||||
#check if name already exists
|
||||
try:
|
||||
|
@ -168,14 +168,14 @@ def joinCourse(token, courseId):
|
|||
#----------------------------------------------------------
|
||||
|
||||
|
||||
@course_routes.route('/api/courses/getCourseByCampusName/<string:name>', methods=["GET"])
|
||||
@course_routes.route('/api/courses/getCoursesByCampus/<string:campusId>', methods=["GET"])
|
||||
@auto.doc()
|
||||
def getCourseByCampusName(name):
|
||||
def getCourseByCampus(campusId):
|
||||
"""
|
||||
<span class="card-title">>This Call will return an array of all courses in a given campus</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- name: 'campus name'
|
||||
- campusId: 1234567890
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
|
@ -188,7 +188,7 @@ def getCourseByCampusName(name):
|
|||
<code>
|
||||
{<br>
|
||||
'courseName': 'Advance Math',<br>
|
||||
'campusName': 'JCE',<br>
|
||||
'campusId': 1234567890,<br>
|
||||
'startDate': '2015-14-3'<br>
|
||||
'endDate': '2015-29-6'<br>
|
||||
'taskFlag': 'False'<br>
|
||||
|
@ -200,7 +200,7 @@ def getCourseByCampusName(name):
|
|||
"""
|
||||
arr = []
|
||||
query = Course.all()
|
||||
query.filter("campusName=", name)
|
||||
query.filter("campusId = ", int(campusId))
|
||||
|
||||
for c in query.run():
|
||||
arr.append(dict(json.loads(c.to_JSON())))
|
||||
|
@ -261,7 +261,7 @@ def getCampusesByUser(token, campusId):
|
|||
arr = []
|
||||
for i in user['courses_id_list']:
|
||||
course = Course.get_by_id(int(i))
|
||||
if course.courseName == campus.title:
|
||||
if course.campusId == campus.key().id():
|
||||
arr.append(dict(json.loads(course.to_JSON())))
|
||||
|
||||
if len(arr) != 0:
|
||||
|
@ -335,64 +335,64 @@ def deleteCourse(token,courseid):
|
|||
return forbidden("lecturer is not owner of course")
|
||||
|
||||
|
||||
@course_routes.route('/api/courses/deleteCoursesByCampus/<string:token>/<string:campusName>', methods=['DELETE'])
|
||||
@auto.doc()
|
||||
def deleteCoursesByCampus(token,campusName):
|
||||
"""
|
||||
<span class="card-title">This Call will delete a specific campus's courses</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
- title: 'campusName'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE <br>
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
202 - Deleted campus
|
||||
<br>
|
||||
204 - No Matching Campus Found
|
||||
<br>
|
||||
....<br>
|
||||
{<br>
|
||||
...<br>
|
||||
}req<br>
|
||||
|
||||
]<br>
|
||||
400 - Bad Request
|
||||
<br>
|
||||
403 - Invalid token or not a lecturer!<br>
|
||||
"""
|
||||
|
||||
if not is_lecturer(token): #todo: change to lecturer id
|
||||
return forbidden("Invalid token or not a lecturer!")
|
||||
|
||||
|
||||
user = get_user_by_token(token)
|
||||
campus = get_campus_by_campusName(campusName)
|
||||
if campus is None:
|
||||
return bad_request("Not a campus!")
|
||||
|
||||
#check user is owner of campus
|
||||
if campus.master_user_id != user.key().id():
|
||||
return forbidden("lecturer is not owner of campus!")
|
||||
|
||||
query = Course.all()
|
||||
|
||||
try:
|
||||
query.filter('campusName =', campusName)
|
||||
except Exception as e:
|
||||
print e
|
||||
return bad_request("invalid course title attribute")
|
||||
|
||||
for c in query.run():
|
||||
db.delete(c)
|
||||
db.save
|
||||
|
||||
return no_content()
|
||||
# @course_routes.route('/api/courses/deleteCoursesByCampus/<string:token>/<string:campusid>', methods=['DELETE'])
|
||||
# @auto.doc()
|
||||
# def deleteCoursesByCampus(token,campusName):
|
||||
# """
|
||||
# <span class="card-title">This Call will delete a specific campus's courses</span>
|
||||
# <br>
|
||||
# <b>Route Parameters</b><br>
|
||||
# - seToken: 'seToken'
|
||||
# - title: 'campusName'
|
||||
# <br>
|
||||
# <br>
|
||||
# <b>Payload</b><br>
|
||||
# - NONE <br>
|
||||
# <br>
|
||||
# <br>
|
||||
# <b>Response</b>
|
||||
# <br>
|
||||
# 202 - Deleted campus
|
||||
# <br>
|
||||
# 204 - No Matching Campus Found
|
||||
# <br>
|
||||
# ....<br>
|
||||
# {<br>
|
||||
# ...<br>
|
||||
# }req<br>
|
||||
#
|
||||
# ]<br>
|
||||
# 400 - Bad Request
|
||||
# <br>
|
||||
# 403 - Invalid token or not a lecturer!<br>
|
||||
# """
|
||||
#
|
||||
# if not is_lecturer(token): #todo: change to lecturer id
|
||||
# return forbidden("Invalid token or not a lecturer!")
|
||||
#
|
||||
#
|
||||
# user = get_user_by_token(token)
|
||||
# campus = get_campus_by_campusName(campusName)
|
||||
# if campus is None:
|
||||
# return bad_request("Not a campus!")
|
||||
#
|
||||
# #check user is owner of campus
|
||||
# if campus.master_user_id != user.key().id():
|
||||
# return forbidden("lecturer is not owner of campus!")
|
||||
#
|
||||
# query = Course.all()
|
||||
#
|
||||
# try:
|
||||
# query.filter('campusName =', campusName)
|
||||
# except Exception as e:
|
||||
# print e
|
||||
# return bad_request("invalid course title attribute")
|
||||
#
|
||||
# for c in query.run():
|
||||
# db.delete(c)
|
||||
# db.save
|
||||
#
|
||||
# return no_content()
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ def create_project(token):
|
|||
- JSON Object, Example: <br>
|
||||
{<br>
|
||||
'projectName': 'Advance Math',<br>
|
||||
'courseName': 'JCE',<br>
|
||||
'courseId': 1234567890,<br>
|
||||
'logo_url': 'http://location.domain.com/image.jpg',<br>
|
||||
'gitRepository': 'http://location.git.com/somthing'<br>
|
||||
}<br>
|
||||
|
@ -62,18 +62,14 @@ def create_project(token):
|
|||
payload = json.loads(request.data)
|
||||
except Exception as e:
|
||||
return bad_request("invalid JSON format")
|
||||
#if not is_lecturer(token): #todo: change to lecturer id
|
||||
# return forbidden("Invalid token or not a lecturer!")
|
||||
|
||||
user = get_user_by_token(token)
|
||||
if user is None:
|
||||
return bad_request("Wrong user Token")
|
||||
|
||||
#todo: check legality
|
||||
|
||||
|
||||
try:
|
||||
project = Project(projectName=payload['projectName'], courseName=payload['courseName'], master_id=user.key().id(), gitRepository=payload['gitRepository'], membersId=[token])
|
||||
project = Project(projectName=payload['projectName'], courseId=payload['courseId'], master_id=user.key().id(), gitRepository=payload['gitRepository'], membersId=[token])
|
||||
except Exception as e:
|
||||
print e
|
||||
return bad_request()
|
||||
|
@ -142,14 +138,14 @@ def joinProject(token, projectId):
|
|||
# GET
|
||||
#----------------------------------------------------------
|
||||
|
||||
@project_routes.route('/api/projects/getProjectsByCourse/<string:name>', methods=["GET"])
|
||||
@project_routes.route('/api/projects/getProjectsByCourse/<string:courseId>', methods=["GET"])
|
||||
@auto.doc()
|
||||
def getProjectsByCourse(name):
|
||||
def getProjectsByCourse(courseId):
|
||||
"""
|
||||
<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'
|
||||
- courseId: 1234567890
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
|
@ -162,7 +158,7 @@ def getProjectsByCourse(name):
|
|||
<code>
|
||||
{<br>
|
||||
'projectName': 'Advance Math',<br>
|
||||
'courseName': 'JCE',<br>
|
||||
'courseId': 123456789,<br>
|
||||
'grade': 98,<br>
|
||||
'logo_url': 'http://location.domain.com/image.jpg',<br>
|
||||
'gitRepository': 'http://location.git.com/somthing',<br>
|
||||
|
@ -175,7 +171,7 @@ def getProjectsByCourse(name):
|
|||
|
||||
arr = []
|
||||
query = Project.all()
|
||||
query.filter("courseName = ", name)
|
||||
query.filter("courseId = ", int(courseId))
|
||||
|
||||
for p in query.run():
|
||||
arr.append(dict(json.loads(p.to_JSON())))
|
||||
|
|
|
@ -5,7 +5,7 @@ from google.appengine.ext import db
|
|||
|
||||
class Course(db.Model):
|
||||
courseName = db.StringProperty(required=True)
|
||||
campusName = db.StringProperty(required=True)
|
||||
campusId = db.IntegerProperty(required=True)
|
||||
master_id = db.IntegerProperty(required=True)
|
||||
# projects = db.StringListProperty(required=True,default=[])
|
||||
startDate = db.DateProperty(required=True)
|
||||
|
@ -14,7 +14,7 @@ class Course(db.Model):
|
|||
|
||||
def to_JSON(self):
|
||||
data = {'courseName' : self.courseName,
|
||||
'campusName' : self.campusName,
|
||||
'campusId' : self.campusName,
|
||||
'master_id' : self.master_id,
|
||||
# 'projects' : self.projects,
|
||||
'startDate' : {
|
||||
|
|
|
@ -5,7 +5,7 @@ from google.appengine.ext import db
|
|||
|
||||
class Project(db.Model):
|
||||
projectName = db.StringProperty(required=True)
|
||||
courseName = db.StringProperty(required=True)
|
||||
courseId = db.IntegerProperty(required=True)
|
||||
master_id = db.IntegerProperty(required=True)
|
||||
grade = db.IntegerProperty(required=True, default=0)
|
||||
logo_url = db.StringProperty(required=False)
|
||||
|
@ -14,7 +14,7 @@ class Project(db.Model):
|
|||
|
||||
def to_JSON(self):
|
||||
data = {'projectName' : self.projectName,
|
||||
'courseName' : self.courseName,
|
||||
'courseId' : self.courseId,
|
||||
'master_id' : self.master_id,
|
||||
'grade' : self.grade,
|
||||
'logo_url' : self.logo_url,
|
||||
|
|
Loading…
Reference in a new issue