Merge branch 'master' of github.com:sagidayan/SE-Hub
This commit is contained in:
commit
352a4c2a8d
2 changed files with 14 additions and 13 deletions
|
@ -57,7 +57,7 @@ def create_course(token):
|
||||||
403 - Invalid token or not a lecturer
|
403 - Invalid token or not a lecturer
|
||||||
"""
|
"""
|
||||||
if not request.data:
|
if not request.data:
|
||||||
return bad_request()
|
return bad_request("no data")
|
||||||
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!")
|
||||||
|
|
||||||
|
@ -77,20 +77,20 @@ 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'],
|
course = Course(courseName=payload['courseName'], campusName=payload['campusName'], 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:
|
||||||
query = Course.all()
|
query = Course.all()
|
||||||
query.filter("courseName = ", payload['courseName'])
|
query.filter("courseName = ", payload['courseName'])
|
||||||
for c in query.run(limit=1):
|
for c in query.run(limit=1):
|
||||||
return forbidden("Campus with same name already exists")
|
return forbidden("Course with same name already exists")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print e
|
print e
|
||||||
|
|
||||||
|
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
print e
|
||||||
return bad_request()
|
return bad_request()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ def getUserByToken(token):
|
||||||
status=200,
|
status=200,
|
||||||
mimetype="application/json") # Real response!
|
mimetype="application/json") # Real response!
|
||||||
|
|
||||||
return bad_request("No User Found")
|
return no_content("No User Found")
|
||||||
|
|
||||||
|
|
||||||
@user_routes.route('/api/users/updateUser/<string:token>', methods=["POST"])
|
@user_routes.route('/api/users/updateUser/<string:token>', methods=["POST"])
|
||||||
|
@ -83,8 +83,8 @@ def updateUser(token):
|
||||||
<b>Payload</b><br>
|
<b>Payload</b><br>
|
||||||
- JSON Object, Example: <br>
|
- JSON Object, Example: <br>
|
||||||
{<br>
|
{<br>
|
||||||
'name': 'Campus name',<br>
|
'name': 'new name',<br>
|
||||||
'isLecturer': '@campus.ac.com',<br>
|
'isLecturer': true<br>
|
||||||
}<br>
|
}<br>
|
||||||
<br>
|
<br>
|
||||||
<b>Response</b>
|
<b>Response</b>
|
||||||
|
@ -100,23 +100,24 @@ def updateUser(token):
|
||||||
try:
|
try:
|
||||||
payload = json.loads(request.data)
|
payload = json.loads(request.data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return bad_request(e)
|
return bad_request()
|
||||||
|
|
||||||
user = get_user_by_token(token)
|
user = get_user_by_token(token)
|
||||||
if user is None:
|
if user is None:
|
||||||
return bad_request("Not a user!")
|
return bad_request("Not a user!")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user.name = payload['user']
|
user.name = payload['name']
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user.isLecturer = payload['isLecturer']
|
user.isLecturer = payload['isLecturer']
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
print e
|
||||||
|
|
||||||
|
|
||||||
|
db.put(user)
|
||||||
|
db.save
|
||||||
return ok("User updated")
|
return ok("User updated")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue