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")
|
||||
|
||||
|
||||
@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()
|
||||
def deleteCampus(token,campusName):
|
||||
def deleteCampus(token,campusid):
|
||||
"""
|
||||
<span class="card-title">This Call will delete a specific campus</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
- title: 'campusName'
|
||||
- campusid: 'campusid'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
|
@ -159,42 +160,33 @@ def deleteCampus(token,campusName):
|
|||
<br>
|
||||
202 - Deleted campus
|
||||
<br>
|
||||
204 - No Matching Campus Found
|
||||
<br>
|
||||
....<br>
|
||||
{<br>
|
||||
...<br>
|
||||
}req<br>
|
||||
|
||||
]<br>
|
||||
400 - Bad Request
|
||||
400 - no such campus
|
||||
<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
|
||||
return forbidden("Invalid token or not a lecturer!")
|
||||
|
||||
|
||||
user = get_user_by_token(token)
|
||||
query = Campus.all()
|
||||
query.filter('master_user_id =',user.key().id())
|
||||
camp = Campus.get_by_id(int(campusid))
|
||||
|
||||
try:
|
||||
query.filter('title =', campusName)
|
||||
except Exception as e:
|
||||
print e
|
||||
return bad_request("invalid campus title attribute")
|
||||
if camp is None:
|
||||
return bad_request("no such campus")
|
||||
|
||||
|
||||
for c in query.run():
|
||||
db.delete(c)
|
||||
if camp.master_user_id == user.key().id():
|
||||
db.delete(camp)
|
||||
db.save
|
||||
return accepted("campus deleted")
|
||||
|
||||
|
||||
return bad_request("no such campus found")
|
||||
|
||||
return forbidden("lecturer is not owner of campus")
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -272,15 +272,21 @@ def getMessagesByCourseName(name):
|
|||
#----------------------------------------------------------
|
||||
# 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()
|
||||
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>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
- title: 'courseName'
|
||||
- courseid: 'courseid'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
|
@ -289,9 +295,7 @@ def deleteCourse(token,courseName):
|
|||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
202 - Deleted campus
|
||||
<br>
|
||||
204 - No Matching Campus Found
|
||||
202 - Deleted Course
|
||||
<br>
|
||||
....<br>
|
||||
{<br>
|
||||
|
@ -299,33 +303,27 @@ def deleteCourse(token,courseName):
|
|||
}req<br>
|
||||
|
||||
]<br>
|
||||
400 - Bad Request
|
||||
400 - no such Course
|
||||
<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
|
||||
return forbidden("Invalid token or not a lecturer!")
|
||||
|
||||
|
||||
user = get_user_by_token(token)
|
||||
query = Course.all()
|
||||
query.filter('master_id =',user.key().id())
|
||||
c = Course.get_by_id(int(courseid))
|
||||
|
||||
try:
|
||||
query.filter('courseName =', courseName)
|
||||
except Exception as e:
|
||||
print e
|
||||
return bad_request("invalid course title attribute")
|
||||
if c is None:
|
||||
return bad_request("no such course")
|
||||
|
||||
|
||||
for c in query.run():
|
||||
if c.master_id == user.key().id():
|
||||
db.delete(c)
|
||||
db.save
|
||||
return accepted("course deleted")
|
||||
|
||||
|
||||
return bad_request("no such course or not owner of course")
|
||||
return forbidden("lecturer is not owner of course")
|
||||
|
||||
|
||||
@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')
|
||||
def documentation():
|
||||
|
|
Loading…
Reference in a new issue