IMPORTANT: alot of function name changes and new Doc

This commit is contained in:
Aran Zaiger 2015-06-28 16:48:01 +03:00
parent 664fcedca0
commit 1574b7e19e
4 changed files with 78 additions and 82 deletions

View file

@ -49,7 +49,7 @@ def create_course(token):
- JSON Object, Example: <br> - JSON Object, Example: <br>
{<br> {<br>
'courseName': 'Advance Math',<br> 'courseName': 'Advance Math',<br>
'campusName': 'JCE',<br> 'campusId': 1234567890,<br>
'startDate': {'year': 2015, 'month' : 4, 'day' : 3},<br> 'startDate': {'year': 2015, 'month' : 4, 'day' : 3},<br>
'endDate': {'year': 2016, 'month' : 5, 'day' : 14}<br> 'endDate': {'year': 2016, 'month' : 5, 'day' : 14}<br>
}<br> }<br>
@ -83,7 +83,7 @@ def create_course(token):
if end_date <= start_date: if end_date <= start_date:
return bad_request("end date cant be before (or same day) 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) startDate=start_date, endDate=end_date)
#check if name already exists #check if name already exists
try: 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() @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> <span class="card-title">>This Call will return an array of all courses in a given campus</span>
<br> <br>
<b>Route Parameters</b><br> <b>Route Parameters</b><br>
- name: 'campus name' - campusId: 1234567890
<br> <br>
<br> <br>
<b>Payload</b><br> <b>Payload</b><br>
@ -188,7 +188,7 @@ def getCourseByCampusName(name):
<code> <code>
{<br> {<br>
'courseName': 'Advance Math',<br> 'courseName': 'Advance Math',<br>
'campusName': 'JCE',<br> 'campusId': 1234567890,<br>
'startDate': '2015-14-3'<br> 'startDate': '2015-14-3'<br>
'endDate': '2015-29-6'<br> 'endDate': '2015-29-6'<br>
'taskFlag': 'False'<br> 'taskFlag': 'False'<br>
@ -200,7 +200,7 @@ def getCourseByCampusName(name):
""" """
arr = [] arr = []
query = Course.all() query = Course.all()
query.filter("campusName=", name) query.filter("campusId = ", int(campusId))
for c in query.run(): for c in query.run():
arr.append(dict(json.loads(c.to_JSON()))) arr.append(dict(json.loads(c.to_JSON())))
@ -261,7 +261,7 @@ def getCampusesByUser(token, campusId):
arr = [] arr = []
for i in user['courses_id_list']: for i in user['courses_id_list']:
course = Course.get_by_id(int(i)) 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()))) arr.append(dict(json.loads(course.to_JSON())))
if len(arr) != 0: if len(arr) != 0:
@ -289,7 +289,7 @@ def getCampusesByUser(token, campusId):
@course_routes.route('/api/courses/deleteCourse/<string:token>/<string:courseid>', methods=['DELETE']) @course_routes.route('/api/courses/deleteCourse/<string:token>/<string:courseid>', methods=['DELETE'])
@auto.doc() @auto.doc()
def deleteCourse(token,courseid): def deleteCourse(token, courseid):
""" """
<span class="card-title">This Call will delete a specific Course</span> <span class="card-title">This Call will delete a specific Course</span>
<br> <br>
@ -335,64 +335,64 @@ def deleteCourse(token,courseid):
return forbidden("lecturer is not owner of course") return forbidden("lecturer is not owner of course")
@course_routes.route('/api/courses/deleteCoursesByCampus/<string:token>/<string:campusName>', methods=['DELETE']) # @course_routes.route('/api/courses/deleteCoursesByCampus/<string:token>/<string:campusid>', methods=['DELETE'])
@auto.doc() # @auto.doc()
def deleteCoursesByCampus(token,campusName): # def deleteCoursesByCampus(token,campusName):
""" # """
<span class="card-title">This Call will delete a specific campus's courses</span> # <span class="card-title">This Call will delete a specific campus's courses</span>
<br> # <br>
<b>Route Parameters</b><br> # <b>Route Parameters</b><br>
- seToken: 'seToken' # - seToken: 'seToken'
- title: 'campusName' # - title: 'campusName'
<br> # <br>
<br> # <br>
<b>Payload</b><br> # <b>Payload</b><br>
- NONE <br> # - NONE <br>
<br> # <br>
<br> # <br>
<b>Response</b> # <b>Response</b>
<br> # <br>
202 - Deleted campus # 202 - Deleted campus
<br> # <br>
204 - No Matching Campus Found # 204 - No Matching Campus Found
<br> # <br>
....<br> # ....<br>
{<br> # {<br>
...<br> # ...<br>
}req<br> # }req<br>
#
]<br> # ]<br>
400 - Bad Request # 400 - Bad Request
<br> # <br>
403 - Invalid token or not a lecturer!<br> # 403 - Invalid token or not a lecturer!<br>
""" # """
#
if not is_lecturer(token): #todo: change to lecturer id # if not is_lecturer(token): #todo: change to lecturer id
return forbidden("Invalid token or not a lecturer!") # return forbidden("Invalid token or not a lecturer!")
#
#
user = get_user_by_token(token) # user = get_user_by_token(token)
campus = get_campus_by_campusName(campusName) # campus = get_campus_by_campusName(campusName)
if campus is None: # if campus is None:
return bad_request("Not a campus!") # return bad_request("Not a campus!")
#
#check user is owner of campus # #check user is owner of campus
if campus.master_user_id != user.key().id(): # if campus.master_user_id != user.key().id():
return forbidden("lecturer is not owner of campus!") # return forbidden("lecturer is not owner of campus!")
#
query = Course.all() # query = Course.all()
#
try: # try:
query.filter('campusName =', campusName) # query.filter('campusName =', campusName)
except Exception as e: # except Exception as e:
print e # print e
return bad_request("invalid course title attribute") # return bad_request("invalid course title attribute")
#
for c in query.run(): # for c in query.run():
db.delete(c) # db.delete(c)
db.save # db.save
#
return no_content() # return no_content()

View file

@ -42,7 +42,7 @@ def create_project(token):
- JSON Object, Example: <br> - JSON Object, Example: <br>
{<br> {<br>
'projectName': 'Advance Math',<br> 'projectName': 'Advance Math',<br>
'courseName': 'JCE',<br> 'courseId': 1234567890,<br>
'logo_url': 'http://location.domain.com/image.jpg',<br> 'logo_url': 'http://location.domain.com/image.jpg',<br>
'gitRepository': 'http://location.git.com/somthing'<br> 'gitRepository': 'http://location.git.com/somthing'<br>
}<br> }<br>
@ -62,18 +62,14 @@ def create_project(token):
payload = json.loads(request.data) payload = json.loads(request.data)
except Exception as e: except Exception as e:
return bad_request("invalid JSON format") 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) user = get_user_by_token(token)
if user is None: if user is None:
return bad_request("Wrong user Token") return bad_request("Wrong user Token")
#todo: check legality
try: 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: except Exception as e:
print e print e
return bad_request() return bad_request()
@ -142,14 +138,14 @@ def joinProject(token, projectId):
# GET # GET
#---------------------------------------------------------- #----------------------------------------------------------
@project_routes.route('/api/projects/getProjectsByCourse/<string:name>', methods=["GET"]) @project_routes.route('/api/projects/getProjectsByCourse/<string:courseId>', methods=["GET"])
@auto.doc() @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> <span class="card-title">>This Call will return an array of all projects in a given course</span>
<br> <br>
<b>Route Parameters</b><br> <b>Route Parameters</b><br>
- name: 'course name' - courseId: 1234567890
<br> <br>
<br> <br>
<b>Payload</b><br> <b>Payload</b><br>
@ -162,7 +158,7 @@ def getProjectsByCourse(name):
<code> <code>
{<br> {<br>
'projectName': 'Advance Math',<br> 'projectName': 'Advance Math',<br>
'courseName': 'JCE',<br> 'courseId': 123456789,<br>
'grade': 98,<br> 'grade': 98,<br>
'logo_url': 'http://location.domain.com/image.jpg',<br> 'logo_url': 'http://location.domain.com/image.jpg',<br>
'gitRepository': 'http://location.git.com/somthing',<br> 'gitRepository': 'http://location.git.com/somthing',<br>
@ -175,7 +171,7 @@ def getProjectsByCourse(name):
arr = [] arr = []
query = Project.all() query = Project.all()
query.filter("courseName = ", name) query.filter("courseId = ", int(courseId))
for p in query.run(): for p in query.run():
arr.append(dict(json.loads(p.to_JSON()))) arr.append(dict(json.loads(p.to_JSON())))

View file

@ -5,7 +5,7 @@ from google.appengine.ext import db
class Course(db.Model): class Course(db.Model):
courseName = db.StringProperty(required=True) courseName = db.StringProperty(required=True)
campusName = db.StringProperty(required=True) campusId = db.IntegerProperty(required=True)
master_id = db.IntegerProperty(required=True) master_id = db.IntegerProperty(required=True)
# projects = db.StringListProperty(required=True,default=[]) # projects = db.StringListProperty(required=True,default=[])
startDate = db.DateProperty(required=True) startDate = db.DateProperty(required=True)
@ -14,7 +14,7 @@ class Course(db.Model):
def to_JSON(self): def to_JSON(self):
data = {'courseName' : self.courseName, data = {'courseName' : self.courseName,
'campusName' : self.campusName, 'campusId' : self.campusName,
'master_id' : self.master_id, 'master_id' : self.master_id,
# 'projects' : self.projects, # 'projects' : self.projects,
'startDate' : { 'startDate' : {

View file

@ -5,7 +5,7 @@ from google.appengine.ext import db
class Project(db.Model): class Project(db.Model):
projectName = db.StringProperty(required=True) projectName = db.StringProperty(required=True)
courseName = db.StringProperty(required=True) courseId = db.IntegerProperty(required=True)
master_id = db.IntegerProperty(required=True) master_id = db.IntegerProperty(required=True)
grade = db.IntegerProperty(required=True, default=0) grade = db.IntegerProperty(required=True, default=0)
logo_url = db.StringProperty(required=False) logo_url = db.StringProperty(required=False)
@ -14,7 +14,7 @@ class Project(db.Model):
def to_JSON(self): def to_JSON(self):
data = {'projectName' : self.projectName, data = {'projectName' : self.projectName,
'courseName' : self.courseName, 'courseId' : self.courseId,
'master_id' : self.master_id, 'master_id' : self.master_id,
'grade' : self.grade, 'grade' : self.grade,
'logo_url' : self.logo_url, 'logo_url' : self.logo_url,