added data verification
This commit is contained in:
parent
ec01ac7a94
commit
e8647534ac
6 changed files with 191 additions and 91 deletions
|
@ -123,7 +123,12 @@ def joinCampus(token, campusId):
|
||||||
|
|
||||||
user = get_user_by_token(token)
|
user = get_user_by_token(token)
|
||||||
|
|
||||||
|
try:
|
||||||
campus = Campus.get_by_id(int(campusId))
|
campus = Campus.get_by_id(int(campusId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
|
|
||||||
if campus is None:
|
if campus is None:
|
||||||
return bad_request("No such course")
|
return bad_request("No such course")
|
||||||
|
|
||||||
|
@ -294,7 +299,12 @@ def getCampusesByUserID(token, id):
|
||||||
if user is None:
|
if user is None:
|
||||||
return forbidden("Invalid Token")
|
return forbidden("Invalid Token")
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
user = get_user_by_id(int(id))
|
user = get_user_by_id(int(id))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
if user is None:
|
if user is None:
|
||||||
return no_content("No User")
|
return no_content("No User")
|
||||||
|
|
||||||
|
@ -351,7 +361,11 @@ def deleteCampus(token,campusId):
|
||||||
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)
|
||||||
|
|
||||||
|
try:
|
||||||
camp = Campus.get_by_id(int(campusId))
|
camp = Campus.get_by_id(int(campusId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
if camp is None:
|
if camp is None:
|
||||||
return bad_request("no such campus")
|
return bad_request("no such campus")
|
||||||
|
|
|
@ -145,7 +145,11 @@ def joinCourse(token, courseId):
|
||||||
if user is None:
|
if user is None:
|
||||||
return bad_request("Wrong user Token")
|
return bad_request("Wrong user Token")
|
||||||
|
|
||||||
|
try:
|
||||||
course = Course.get_by_id(int(courseId))
|
course = Course.get_by_id(int(courseId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
if course is None:
|
if course is None:
|
||||||
return bad_request("No such course")
|
return bad_request("No such course")
|
||||||
|
|
||||||
|
@ -205,7 +209,12 @@ def getAllCoursesByCampus(token, campusId):
|
||||||
|
|
||||||
arr = []
|
arr = []
|
||||||
query = Course.all()
|
query = Course.all()
|
||||||
|
|
||||||
|
try:
|
||||||
query.filter("campusId = ", int(campusId))
|
query.filter("campusId = ", int(campusId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
|
|
||||||
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())))
|
||||||
|
@ -258,7 +267,11 @@ def getUserCoursesByCampus(token, campusId):
|
||||||
if user is None:
|
if user is None:
|
||||||
return bad_request("Bad user Token")
|
return bad_request("Bad user Token")
|
||||||
|
|
||||||
|
try:
|
||||||
campus = Campus.get_by_id(int(campusId))
|
campus = Campus.get_by_id(int(campusId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
if campus is None:
|
if campus is None:
|
||||||
return bad_request("No such Campus")
|
return bad_request("No such Campus")
|
||||||
|
|
||||||
|
@ -318,6 +331,11 @@ def getCoursesByUser(token, userId):
|
||||||
if user is None:
|
if user is None:
|
||||||
return bad_request("Bad user Token")
|
return bad_request("Bad user Token")
|
||||||
|
|
||||||
|
try:
|
||||||
|
otherUser = User.get_by_id(int(userId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
otherUser = User.get_by_id(int(userId))
|
otherUser = User.get_by_id(int(userId))
|
||||||
if otherUser is None:
|
if otherUser is None:
|
||||||
return bad_request("Bad user Id")
|
return bad_request("Bad user Id")
|
||||||
|
@ -349,9 +367,9 @@ def getCoursesByUser(token, userId):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@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>
|
||||||
|
@ -383,7 +401,11 @@ def deleteCourse(token, courseid):
|
||||||
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)
|
||||||
c = Course.get_by_id(int(courseid))
|
|
||||||
|
try:
|
||||||
|
c = Course.get_by_id(int(courseId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
if c is None:
|
if c is None:
|
||||||
return bad_request("no such course")
|
return bad_request("no such course")
|
||||||
|
|
|
@ -153,7 +153,11 @@ def getMessagesByGroup(token, groupId):
|
||||||
|
|
||||||
arr = []
|
arr = []
|
||||||
query = Message.all()
|
query = Message.all()
|
||||||
|
|
||||||
|
try:
|
||||||
query.filter("groupId = ", int(groupId))
|
query.filter("groupId = ", int(groupId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
for m in query.run():
|
for m in query.run():
|
||||||
msgDic = dict(json.loads(m.to_JSON()))
|
msgDic = dict(json.loads(m.to_JSON()))
|
||||||
|
@ -222,7 +226,12 @@ def deleteMessage(token, msgId):
|
||||||
if user is None:
|
if user is None:
|
||||||
return bad_request("No such User")
|
return bad_request("No such User")
|
||||||
|
|
||||||
|
try:
|
||||||
msg = Message.get_by_id(int(msgId))
|
msg = Message.get_by_id(int(msgId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
|
|
||||||
if msg is None:
|
if msg is None:
|
||||||
return bad_request("No such Message")
|
return bad_request("No such Message")
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,12 @@ def joinProject(token, projectId):
|
||||||
if user is None:
|
if user is None:
|
||||||
return bad_request("Wrong user Token")
|
return bad_request("Wrong user Token")
|
||||||
|
|
||||||
|
try:
|
||||||
project = Project.get_by_id(int(projectId))
|
project = Project.get_by_id(int(projectId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
|
|
||||||
if project is None:
|
if project is None:
|
||||||
return bad_request("No such Project")
|
return bad_request("No such Project")
|
||||||
|
|
||||||
|
@ -193,7 +198,11 @@ def getProjectsByCourse(token, courseId):
|
||||||
|
|
||||||
arr = []
|
arr = []
|
||||||
query = Project.all()
|
query = Project.all()
|
||||||
|
|
||||||
|
try:
|
||||||
query.filter("courseId = ", int(courseId))
|
query.filter("courseId = ", int(courseId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
for p in query.run():
|
for p in query.run():
|
||||||
proj = dict(json.loads(p.to_JSON()))
|
proj = dict(json.loads(p.to_JSON()))
|
||||||
|
@ -305,7 +314,11 @@ def deleteProject(token,projectId):
|
||||||
user = get_user_by_token(token)
|
user = get_user_by_token(token)
|
||||||
if user is None:
|
if user is None:
|
||||||
return bad_request("Bad user Token")
|
return bad_request("Bad user Token")
|
||||||
|
|
||||||
|
try:
|
||||||
p = Project.get_by_id(int(projectId))
|
p = Project.get_by_id(int(projectId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
if p is None:
|
if p is None:
|
||||||
return bad_request("no such Project")
|
return bad_request("no such Project")
|
||||||
|
|
|
@ -192,7 +192,11 @@ def getAllTasksByCourse(token, courseId):
|
||||||
|
|
||||||
arr = []
|
arr = []
|
||||||
query = Task.all()
|
query = Task.all()
|
||||||
query.filter("courseId = ", courseId)
|
|
||||||
|
try:
|
||||||
|
query.filter("courseId = ", int(courseId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
for t in query.run():
|
for t in query.run():
|
||||||
taskDic =dict(json.loads(t.to_JSON()))
|
taskDic =dict(json.loads(t.to_JSON()))
|
||||||
|
@ -254,7 +258,11 @@ def getAllFutureTasks(token, courseId):
|
||||||
|
|
||||||
arr = []
|
arr = []
|
||||||
query = Task.all()
|
query = Task.all()
|
||||||
query.filter("courseId = ", courseId)
|
|
||||||
|
try:
|
||||||
|
query.filter("courseId = ", int(courseId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
for t in query.run():
|
for t in query.run():
|
||||||
taskDic =dict(json.loads(t.to_JSON()))
|
taskDic =dict(json.loads(t.to_JSON()))
|
||||||
|
@ -324,7 +332,11 @@ def getTaskComponents(token, taskId):
|
||||||
|
|
||||||
arr = []
|
arr = []
|
||||||
query = TaskComponent.all()
|
query = TaskComponent.all()
|
||||||
query.filter("taskId = ", taskId)
|
|
||||||
|
try:
|
||||||
|
query.filter("taskId = ", int(taskId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
for tc in query.run():
|
for tc in query.run():
|
||||||
arr.append(dict(json.loads(tc.to_JSON())))
|
arr.append(dict(json.loads(tc.to_JSON())))
|
||||||
|
@ -384,7 +396,11 @@ 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)
|
||||||
|
|
||||||
|
try:
|
||||||
c = Task.get_by_id(int(taskId))
|
c = Task.get_by_id(int(taskId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
if c is None:
|
if c is None:
|
||||||
return bad_request("no such Task")
|
return bad_request("no such Task")
|
||||||
|
@ -432,7 +448,12 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
t = Task.get_by_id(int(taskId))
|
t = Task.get_by_id(int(taskId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
if t is None:
|
if t is None:
|
||||||
return bad_request("no such Task")
|
return bad_request("no such Task")
|
||||||
|
|
|
@ -145,63 +145,63 @@ def updateUser(token):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@user_routes.route('/api/users/addUserToCampus/<string:token>', methods=["PUT"])
|
# @user_routes.route('/api/users/addUserToCampus/<string:token>', methods=["PUT"])
|
||||||
@auto.doc()
|
# @auto.doc()
|
||||||
def addUserToCampus(token):
|
# def addUserToCampus(token):
|
||||||
"""
|
# """
|
||||||
<span class="card-title">>This Call will add a Campus to user Campus list</span>
|
# <span class="card-title">>This Call will add a Campus to user Campus list</span>
|
||||||
<br>
|
# <br>
|
||||||
<b>Route Parameters</b><br>
|
# <b>Route Parameters</b><br>
|
||||||
- seToken: 'seToken'
|
# - seToken: 'seToken'
|
||||||
<br>
|
# <br>
|
||||||
<br>
|
# <br>
|
||||||
<b>Payload</b><br>
|
# <b>Payload</b><br>
|
||||||
- JSON Object, Example: <br>
|
# - JSON Object, Example: <br>
|
||||||
{<br>
|
# {<br>
|
||||||
'campusId': 1234567890<br>
|
# 'campusId': 1234567890<br>
|
||||||
}<br>
|
# }<br>
|
||||||
<br>
|
# <br>
|
||||||
<b>Response</b>
|
# <b>Response</b>
|
||||||
<br>
|
# <br>
|
||||||
200 - User updated
|
# 200 - User updated
|
||||||
<br>
|
# <br>
|
||||||
400 - Bad Request
|
# 400 - Bad Request
|
||||||
"""
|
# """
|
||||||
|
#
|
||||||
if not request.data:
|
# if not request.data:
|
||||||
return bad_request()
|
# return bad_request()
|
||||||
|
#
|
||||||
try:
|
# try:
|
||||||
payload = json.loads(request.data)
|
# payload = json.loads(request.data)
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
print e
|
# print e
|
||||||
return bad_request()
|
# return bad_request()
|
||||||
|
#
|
||||||
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)
|
||||||
|
#
|
||||||
#check Campus Exists
|
# #check Campus Exists
|
||||||
campus = Campus.get_by_id(payload['campusId'])
|
# campus = Campus.get_by_id(payload['campusId'])
|
||||||
if campus is None:
|
# if campus is None:
|
||||||
return bad_request("No such Campus!")
|
# return bad_request("No such Campus!")
|
||||||
|
#
|
||||||
try:
|
# try:
|
||||||
if str(payload['campusId']) in user.campuses_id_list:
|
# if str(payload['campusId']) in user.campuses_id_list:
|
||||||
return accepted("Already a member of that campus")
|
# return accepted("Already a member of that campus")
|
||||||
|
#
|
||||||
user.campuses_id_list.append(str(payload['campusId']))
|
# user.campuses_id_list.append(str(payload['campusId']))
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
print e
|
# print e
|
||||||
return bad_request()
|
# return bad_request()
|
||||||
|
#
|
||||||
|
#
|
||||||
db.put(user)
|
# db.put(user)
|
||||||
db.save
|
# db.save
|
||||||
return Response(response=user.to_JSON(),
|
# return Response(response=user.to_JSON(),
|
||||||
status=200,
|
# status=200,
|
||||||
mimetype="application/json") # Real response!
|
# mimetype="application/json") # Real response!
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
|
@ -314,7 +314,11 @@ def getUserById(token, id):
|
||||||
if get_user_by_token(token) is None:
|
if get_user_by_token(token) is None:
|
||||||
return forbidden('Invalid Token')
|
return forbidden('Invalid Token')
|
||||||
|
|
||||||
|
try:
|
||||||
u = get_user_by_id(int(id))
|
u = get_user_by_id(int(id))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
if u is None:
|
if u is None:
|
||||||
return no_content('No user Found')
|
return no_content('No user Found')
|
||||||
|
|
||||||
|
@ -371,7 +375,11 @@ def getUsersByCampus(token, campusId):
|
||||||
if user is None:
|
if user is None:
|
||||||
return bad_request("Bad User Token")
|
return bad_request("Bad User Token")
|
||||||
|
|
||||||
|
try:
|
||||||
campus = Campus.get_by_id(int(campusId))
|
campus = Campus.get_by_id(int(campusId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
if campus is None:
|
if campus is None:
|
||||||
return bad_request("No such Campus")
|
return bad_request("No such Campus")
|
||||||
|
|
||||||
|
@ -432,7 +440,11 @@ def getUsersByCourse(token, courseId):
|
||||||
if user is None:
|
if user is None:
|
||||||
return bad_request("Bad User Token")
|
return bad_request("Bad User Token")
|
||||||
|
|
||||||
|
try:
|
||||||
course = Course.get_by_id(int(courseId))
|
course = Course.get_by_id(int(courseId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
if course is None:
|
if course is None:
|
||||||
return bad_request("No such Course")
|
return bad_request("No such Course")
|
||||||
|
|
||||||
|
@ -493,7 +505,11 @@ def getUsersByProject(token, projectId):
|
||||||
if user is None:
|
if user is None:
|
||||||
return bad_request("Bad User Token")
|
return bad_request("Bad User Token")
|
||||||
|
|
||||||
|
try:
|
||||||
project = Project.get_by_id(int(projectId))
|
project = Project.get_by_id(int(projectId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
if project is None:
|
if project is None:
|
||||||
return bad_request("No such Project")
|
return bad_request("No such Project")
|
||||||
|
|
||||||
|
@ -544,7 +560,11 @@ def removeUserFromCampus(token, userId, campusId):
|
||||||
if requestingUser is None:
|
if requestingUser is None:
|
||||||
return bad_request("Bad User Token")
|
return bad_request("Bad User Token")
|
||||||
|
|
||||||
|
try:
|
||||||
userToRemove = User.get_by_id(int(userId))
|
userToRemove = User.get_by_id(int(userId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
if userToRemove is None:
|
if userToRemove is None:
|
||||||
return bad_request("No such user to remove")
|
return bad_request("No such user to remove")
|
||||||
|
|
||||||
|
@ -573,9 +593,6 @@ def removeUserFromCampus(token, userId, campusId):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@user_routes.route('/api/users/removeUserFromCourse/<string:token>/<string:userId>/<string:courseId>', methods=["PUT"])
|
@user_routes.route('/api/users/removeUserFromCourse/<string:token>/<string:userId>/<string:courseId>', methods=["PUT"])
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def removeUserFromCourse(token, userId, courseId):
|
def removeUserFromCourse(token, userId, courseId):
|
||||||
|
@ -604,7 +621,11 @@ def removeUserFromCourse(token, userId, courseId):
|
||||||
if requestingUser is None:
|
if requestingUser is None:
|
||||||
return bad_request("Bad User Token")
|
return bad_request("Bad User Token")
|
||||||
|
|
||||||
|
try:
|
||||||
userToRemove = User.get_by_id(int(userId))
|
userToRemove = User.get_by_id(int(userId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
if userToRemove is None:
|
if userToRemove is None:
|
||||||
return bad_request("No such user to remove")
|
return bad_request("No such user to remove")
|
||||||
|
|
||||||
|
@ -635,9 +656,6 @@ def removeUserFromCourse(token, userId, courseId):
|
||||||
mimetype="application/json") # Real response!
|
mimetype="application/json") # Real response!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@user_routes.route('/api/users/removeUserFromProject/<string:token>/<string:userId>/<string:projectId>', methods=["PUT"])
|
@user_routes.route('/api/users/removeUserFromProject/<string:token>/<string:userId>/<string:projectId>', methods=["PUT"])
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def removeUserFromProject(token, userId, projectId):
|
def removeUserFromProject(token, userId, projectId):
|
||||||
|
@ -666,7 +684,12 @@ def removeUserFromProject(token, userId, projectId):
|
||||||
if requestingUser is None:
|
if requestingUser is None:
|
||||||
return bad_request("Bad User Token")
|
return bad_request("Bad User Token")
|
||||||
|
|
||||||
|
try:
|
||||||
userToRemove = User.get_by_id(int(userId))
|
userToRemove = User.get_by_id(int(userId))
|
||||||
|
except Exception as e:
|
||||||
|
return bad_request("Bad id format")
|
||||||
|
|
||||||
|
|
||||||
if userToRemove is None:
|
if userToRemove is None:
|
||||||
return bad_request("No such user to remove")
|
return bad_request("No such user to remove")
|
||||||
|
|
||||||
|
@ -698,8 +721,6 @@ def removeUserFromProject(token, userId, projectId):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
# DOCUMENTATION
|
# DOCUMENTATION
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue