From 379ede2617e561ffe03b4ecc6c5d783f834fe7be Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 15 Jun 2015 16:32:35 +0300 Subject: [PATCH 1/2] models - added master_id --- models/Course.py | 2 ++ models/Project.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/models/Course.py b/models/Course.py index 7b2ac75..4b3abe5 100644 --- a/models/Course.py +++ b/models/Course.py @@ -6,6 +6,7 @@ from google.appengine.ext import db class Course(db.Model): courseName = db.StringProperty(required=True) campusName = db.StringProperty(required=True) + master_id = db.IntegerProperty(required=True) projects = db.StringListProperty(required=True,default=[]) startDate = db.DateProperty(required=True) endDate = db.DateProperty(required=True) @@ -13,6 +14,7 @@ class Course(db.Model): def to_JSON(self): data = {'courseName' : self.courseName, 'campusName' : self.campusName, + 'master_id' : self.master_id, 'projects' : self.projects, 'startDate' : { 'year': self.startDate.year, diff --git a/models/Project.py b/models/Project.py index e165c58..97db04e 100644 --- a/models/Project.py +++ b/models/Project.py @@ -5,7 +5,7 @@ from google.appengine.ext import db class Project(db.Model): projectName = db.StringProperty(required=True) - masterId = db.IntegerProperty(required=True) + master_id = db.IntegerProperty(required=True) grade = db.IntegerProperty(required=True, default=0) logo_url = db.StringProperty(required=False) gitRepository = db.StringProperty(required=True) @@ -13,7 +13,7 @@ class Project(db.Model): def to_JSON(self): data = {'projectName' : self.projectName, - 'masterId' : self.masterId, + 'master_id' : self.master_id, 'grade' : self.grade, 'logo_url' : self.logo_url, 'gitRepository' : self.gitRepository, From f7172ab983ab1994fbad5c394709ccacf63e2d19 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 15 Jun 2015 16:32:59 +0300 Subject: [PATCH 2/2] 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