From 2ebd7392e4d8d4e1d157b2dec973536c00f27bc5 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Tue, 16 Jun 2015 22:11:33 +0300 Subject: [PATCH 1/3] fix bug #25 --- SE_API/UserRoutes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SE_API/UserRoutes.py b/SE_API/UserRoutes.py index c0471c3..f1e9382 100644 --- a/SE_API/UserRoutes.py +++ b/SE_API/UserRoutes.py @@ -67,7 +67,7 @@ def getUserByToken(token): status=200, mimetype="application/json") # Real response! - return bad_request("No User Found") + return no_content("No User Found") @user_routes.route('/api/users/updateUser/', methods=["POST"]) From d428da5df0d53f703f99e97e02ebad2536bdc971 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Tue, 16 Jun 2015 22:16:11 +0300 Subject: [PATCH 2/3] added a missing parameter (master_id) that made function not usable --- SE_API/CourseRoutes.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SE_API/CourseRoutes.py b/SE_API/CourseRoutes.py index 4bae4ea..5713db2 100644 --- a/SE_API/CourseRoutes.py +++ b/SE_API/CourseRoutes.py @@ -57,7 +57,7 @@ def create_course(token): 403 - Invalid token or not a lecturer """ if not request.data: - return bad_request() + return bad_request("no data") if not is_lecturer(token): #todo: change to lecturer id return forbidden("Invalid token or not a lecturer!") @@ -77,20 +77,20 @@ def create_course(token): if end_date <= 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) - #check if name already exists try: query = Course.all() query.filter("courseName = ", payload['courseName']) 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: print e - except Exception: + except Exception as e: + print e return bad_request() From 4bb17157d0eebebc0d2d97594cbfb0fbea43cd5f Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Tue, 16 Jun 2015 22:28:05 +0300 Subject: [PATCH 3/3] fix updateUser - added save ro DB fix parameter name fix documentation --- SE_API/UserRoutes.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/SE_API/UserRoutes.py b/SE_API/UserRoutes.py index f1e9382..4073229 100644 --- a/SE_API/UserRoutes.py +++ b/SE_API/UserRoutes.py @@ -83,8 +83,8 @@ def updateUser(token): Payload
- JSON Object, Example:
{
- 'name': 'Campus name',
- 'isLecturer': '@campus.ac.com',
+ 'name': 'new name',
+ 'isLecturer': true
}

Response @@ -100,23 +100,24 @@ def updateUser(token): try: payload = json.loads(request.data) except Exception as e: - return bad_request(e) + return bad_request() user = get_user_by_token(token) if user is None: return bad_request("Not a user!") try: - user.name = payload['user'] + user.name = payload['name'] except Exception: pass try: user.isLecturer = payload['isLecturer'] - except Exception: - pass - + except Exception as e: + print e + db.put(user) + db.save return ok("User updated")