From f7172ab983ab1994fbad5c394709ccacf63e2d19 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 15 Jun 2015 16:32:59 +0300 Subject: [PATCH] added function and changed functions path --- SE_API/CampusRoutes.py | 64 ++++++++++++++++++++++++++++++++++++++--- SE_API/ProjectRoutes.py | 3 +- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/SE_API/CampusRoutes.py b/SE_API/CampusRoutes.py index 8a5d5d9..93afc55 100644 --- a/SE_API/CampusRoutes.py +++ b/SE_API/CampusRoutes.py @@ -53,13 +53,25 @@ def create_campus(token): """ if not request.data: return bad_request() - payload = json.loads(request.data) if not is_lecturer(token): #todo: change to lecturer id return forbidden("Invalid token or not a lecturer!") - user = get_user_by_token(token) + #try to parse payload + try: + payload = json.loads(request.data) + except Exception as e: + return bad_request(e) - #todo: check legality + #check if name already exists + try: + query = Campus.all() + query.filter("title = ", payload['title']) + for c in query.run(limit=1): + return forbidden("Campus with same name already exists") + except Exception as e: + print e + + user = get_user_by_token(token) try: campus = Campus(title=payload['title'], email_ending=payload['email_ending'], master_user_id=user.key().id(), avatar_url=payload['avatar_url']) @@ -76,7 +88,7 @@ def create_campus(token): -@campus_routes.route('/api/campuses/', methods=['GET']) +@campus_routes.route('/api/campuses/getAll/', methods=['GET']) @auto.doc() def get_campuses(token): """ @@ -129,6 +141,50 @@ def get_campuses(token): +@campus_routes.route('/api/campuses/getCampusId/', methods=["GET"]) +@auto.doc() +def getCampusId(name): + ''' + This Function is will Activate a user and add tha campus to it +
+ Route Parameters
+ - validation_token: 'seToken|email_suffix' +
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ + {
+ 'username' : 'github_username',
+ 'name' : 'Bob Dylan',
+ 'email' : 'email@domain.com',
+ 'isLecturer' : true,
+ 'seToken' : 'dds2d-sfvvsf-qqq-fdf33-sfaa',
+ 'avatar_url' : 'http://location.domain.com/image.jpg',
+ 'isFirstLogin' : false,
+ 'campuses_id_list': ['22314','243512',...,'356'],
+ 'classes_id_list': ['22314','243512',...,'356']
+ } +
+
+ 403 - Invalid Token + ''' + query = Campus.all() + query.filter("title = ", name) + + for c in query.run(limit=5): + return Response(response=c.key().id(), + status=200, + mimetype="application/json") # Real response! + + return bad_request("No Campus Found") + + @campus_routes.route('/api/campuses/help') def documentation(): diff --git a/SE_API/ProjectRoutes.py b/SE_API/ProjectRoutes.py index ae089df..44c2015 100644 --- a/SE_API/ProjectRoutes.py +++ b/SE_API/ProjectRoutes.py @@ -77,7 +77,7 @@ def create_project(token,id): -@project_routes.route('/api/projects/get/', methods=['GET']) +@project_routes.route('/api/projects/getAll/', methods=['GET']) @auto.doc() def get_projects(token): """ @@ -136,6 +136,7 @@ def get_campuses(token): + @project_routes.route('/api/projects/help') def documentation(): return auto.html() \ No newline at end of file