added delete functions + doc to campus, course, project
This commit is contained in:
parent
431a36760d
commit
e9e10bd980
3 changed files with 77 additions and 40 deletions
|
@ -140,15 +140,16 @@ def get_campuses(token):
|
||||||
return forbidden("Invalid Token")
|
return forbidden("Invalid Token")
|
||||||
|
|
||||||
|
|
||||||
@campus_routes.route('/api/campuses/deleteCampus/<string:token>/<string:campusName>', methods=['DELETE'])
|
|
||||||
|
@campus_routes.route('/api/campuses/deleteCampus/<string:token>/<string:campusid>', methods=['DELETE'])
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def deleteCampus(token,campusName):
|
def deleteCampus(token,campusid):
|
||||||
"""
|
"""
|
||||||
<span class="card-title">This Call will delete a specific campus</span>
|
<span class="card-title">This Call will delete a specific campus</span>
|
||||||
<br>
|
<br>
|
||||||
<b>Route Parameters</b><br>
|
<b>Route Parameters</b><br>
|
||||||
- seToken: 'seToken'
|
- seToken: 'seToken'
|
||||||
- title: 'campusName'
|
- campusid: 'campusid'
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<b>Payload</b><br>
|
<b>Payload</b><br>
|
||||||
|
@ -159,42 +160,33 @@ def deleteCampus(token,campusName):
|
||||||
<br>
|
<br>
|
||||||
202 - Deleted campus
|
202 - Deleted campus
|
||||||
<br>
|
<br>
|
||||||
204 - No Matching Campus Found
|
|
||||||
<br>
|
|
||||||
....<br>
|
....<br>
|
||||||
{<br>
|
{<br>
|
||||||
...<br>
|
...<br>
|
||||||
}req<br>
|
}req<br>
|
||||||
|
|
||||||
]<br>
|
]<br>
|
||||||
400 - Bad Request
|
400 - no such campus
|
||||||
<br>
|
<br>
|
||||||
403 - Invalid token or not a lecturer!<br>
|
403 - Invalid token or not a lecturer or lecturer is not owner of campus!<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)
|
||||||
query = Campus.all()
|
camp = Campus.get_by_id(int(campusid))
|
||||||
query.filter('master_user_id =',user.key().id())
|
|
||||||
|
|
||||||
try:
|
if camp is None:
|
||||||
query.filter('title =', campusName)
|
return bad_request("no such campus")
|
||||||
except Exception as e:
|
|
||||||
print e
|
|
||||||
return bad_request("invalid campus title attribute")
|
|
||||||
|
|
||||||
|
|
||||||
for c in query.run():
|
if camp.master_user_id == user.key().id():
|
||||||
db.delete(c)
|
db.delete(camp)
|
||||||
db.save
|
db.save
|
||||||
return accepted("campus deleted")
|
return accepted("campus deleted")
|
||||||
|
|
||||||
|
return forbidden("lecturer is not owner of campus")
|
||||||
return bad_request("no such campus found")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -272,15 +272,21 @@ def getMessagesByCourseName(name):
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
# DELETE
|
# DELETE
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
@course_routes.route('/api/courses/deleteCourse/<string:token>/<string:courseName>', methods=['DELETE'])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@course_routes.route('/api/courses/deleteCourse/<string:token>/<string:courseid>', methods=['DELETE'])
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def deleteCourse(token,courseName):
|
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>
|
||||||
<b>Route Parameters</b><br>
|
<b>Route Parameters</b><br>
|
||||||
- seToken: 'seToken'
|
- seToken: 'seToken'
|
||||||
- title: 'courseName'
|
- courseid: 'courseid'
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<b>Payload</b><br>
|
<b>Payload</b><br>
|
||||||
|
@ -289,9 +295,7 @@ def deleteCourse(token,courseName):
|
||||||
<br>
|
<br>
|
||||||
<b>Response</b>
|
<b>Response</b>
|
||||||
<br>
|
<br>
|
||||||
202 - Deleted campus
|
202 - Deleted Course
|
||||||
<br>
|
|
||||||
204 - No Matching Campus Found
|
|
||||||
<br>
|
<br>
|
||||||
....<br>
|
....<br>
|
||||||
{<br>
|
{<br>
|
||||||
|
@ -299,33 +303,27 @@ def deleteCourse(token,courseName):
|
||||||
}req<br>
|
}req<br>
|
||||||
|
|
||||||
]<br>
|
]<br>
|
||||||
400 - Bad Request
|
400 - no such Course
|
||||||
<br>
|
<br>
|
||||||
403 - Invalid token or not a lecturer!<br>
|
403 - Invalid token or not a lecturer or lecturer is not owner of Course!<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)
|
||||||
query = Course.all()
|
c = Course.get_by_id(int(courseid))
|
||||||
query.filter('master_id =',user.key().id())
|
|
||||||
|
|
||||||
try:
|
if c is None:
|
||||||
query.filter('courseName =', courseName)
|
return bad_request("no such course")
|
||||||
except Exception as e:
|
|
||||||
print e
|
|
||||||
return bad_request("invalid course title attribute")
|
|
||||||
|
|
||||||
|
|
||||||
for c in query.run():
|
if c.master_id == user.key().id():
|
||||||
db.delete(c)
|
db.delete(c)
|
||||||
db.save
|
db.save
|
||||||
return accepted("course deleted")
|
return accepted("course deleted")
|
||||||
|
|
||||||
|
return forbidden("lecturer is not owner of course")
|
||||||
return bad_request("no such course or 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:campusName>', methods=['DELETE'])
|
||||||
|
|
|
@ -130,6 +130,53 @@ def getProjectsByCourseName(name):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@project_routes.route('/api/projects/deleteProject/<string:token>/<string:projectid>', methods=['DELETE'])
|
||||||
|
@auto.doc()
|
||||||
|
def deleteProject(token,projectid):
|
||||||
|
"""
|
||||||
|
<span class="card-title">This Call will delete a specific Project</span>
|
||||||
|
<br>
|
||||||
|
<b>Route Parameters</b><br>
|
||||||
|
- seToken: 'seToken'
|
||||||
|
- courseid: 'projectid'
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<b>Payload</b><br>
|
||||||
|
- NONE <br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<b>Response</b>
|
||||||
|
<br>
|
||||||
|
202 - Deleted Project
|
||||||
|
<br>
|
||||||
|
....<br>
|
||||||
|
{<br>
|
||||||
|
...<br>
|
||||||
|
}req<br>
|
||||||
|
|
||||||
|
]<br>
|
||||||
|
400 - no such Project
|
||||||
|
<br>
|
||||||
|
403 - Invalid token or not the owner of Project!<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)
|
||||||
|
p = Project.get_by_id(int(projectid))
|
||||||
|
|
||||||
|
if p is None:
|
||||||
|
return bad_request("no such Project")
|
||||||
|
|
||||||
|
if p.master_id == user.key().id():
|
||||||
|
db.delete(p)
|
||||||
|
db.save
|
||||||
|
return accepted("Project deleted")
|
||||||
|
|
||||||
|
return forbidden("user is not owner of Project")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@project_routes.route('/api/projects/help')
|
@project_routes.route('/api/projects/help')
|
||||||
def documentation():
|
def documentation():
|
||||||
|
|
Loading…
Reference in a new issue