From 5b0d67152f034e69ae3911e13b36c10036561c05 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 15 Jun 2015 16:53:56 +0300 Subject: [PATCH 1/8] removed function --- SE_API/CampusRoutes.py | 45 ------------------------------------------ 1 file changed, 45 deletions(-) diff --git a/SE_API/CampusRoutes.py b/SE_API/CampusRoutes.py index 93afc55..43afbf1 100644 --- a/SE_API/CampusRoutes.py +++ b/SE_API/CampusRoutes.py @@ -141,51 +141,6 @@ 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(): return auto.html() \ No newline at end of file From 26c66842b4b409978eac2cc594816ef4036729dc Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 15 Jun 2015 16:54:12 +0300 Subject: [PATCH 2/8] added getCourseByCampusName function --- SE_API/CourseRoutes.py | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/SE_API/CourseRoutes.py b/SE_API/CourseRoutes.py index 6b76f3b..4131674 100644 --- a/SE_API/CourseRoutes.py +++ b/SE_API/CourseRoutes.py @@ -83,6 +83,49 @@ def create_course(token): +@course_routes.route('/api/courses/getCourseByCampusName/', methods=["GET"]) +@auto.doc() +def getCourseByCampusName(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 = Course.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") + @course_routes.route('/api/courses/help') def documentation(): return auto.html() \ No newline at end of file From ab4cdab12da2ccb721b2fd938567e317419d7398 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 15 Jun 2015 18:34:02 +0300 Subject: [PATCH 3/8] removed project list from course and added course to project --- models/Course.py | 4 ++-- models/Project.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/models/Course.py b/models/Course.py index 4b3abe5..fd2dc08 100644 --- a/models/Course.py +++ b/models/Course.py @@ -7,7 +7,7 @@ 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=[]) + # projects = db.StringListProperty(required=True,default=[]) startDate = db.DateProperty(required=True) endDate = db.DateProperty(required=True) @@ -15,7 +15,7 @@ class Course(db.Model): data = {'courseName' : self.courseName, 'campusName' : self.campusName, 'master_id' : self.master_id, - 'projects' : self.projects, + # 'projects' : self.projects, 'startDate' : { 'year': self.startDate.year, 'month': self.startDate.month, diff --git a/models/Project.py b/models/Project.py index 97db04e..579ecdd 100644 --- a/models/Project.py +++ b/models/Project.py @@ -5,6 +5,7 @@ from google.appengine.ext import db class Project(db.Model): projectName = db.StringProperty(required=True) + courseName = db.StringProperty(required=True) master_id = db.IntegerProperty(required=True) grade = db.IntegerProperty(required=True, default=0) logo_url = db.StringProperty(required=False) @@ -13,6 +14,7 @@ class Project(db.Model): def to_JSON(self): data = {'projectName' : self.projectName, + 'courseName' : self.courseName, 'master_id' : self.master_id, 'grade' : self.grade, 'logo_url' : self.logo_url, From 991d6a73bcd7083c1ef5c06026296ad8b58d2f6c Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 15 Jun 2015 18:35:47 +0300 Subject: [PATCH 4/8] added some data verifiaction --- SE_API/CourseRoutes.py | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/SE_API/CourseRoutes.py b/SE_API/CourseRoutes.py index 4131674..95a2539 100644 --- a/SE_API/CourseRoutes.py +++ b/SE_API/CourseRoutes.py @@ -48,13 +48,16 @@ def create_course(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) - #todo: check legality + #try to parse payload + try: + payload = json.loads(request.data) + except Exception as e: + return bad_request(e) try: @@ -64,10 +67,20 @@ def create_course(token): course = Course(courseName=payload['courseName'], campusName=payload['campusName'], startDate=start_date, endDate=end_date) + #check if name already exists try: - course.projects=payload['projects'] - except Exception: - pass + query = Course.all() + query.filter("courseName = ", payload['courseName']) + for c in query.run(limit=1): + return forbidden("Campus with same name already exists") + except Exception as e: + print e + + #check if and projects needs to be added + # try: + # course.projects=payload['projects'] + # except Exception: + # pass except Exception: @@ -116,15 +129,23 @@ def getCourseByCampusName(name):
403 - Invalid Token ''' + + arr = [] query = Course.all() - query.filter("title = ", name) + query.filter("campusName = ", name) - for c in query.run(limit=5): - return Response(response=c.key().id(), + for c in query.run(): + arr.append(dict(json.loads(c.to_JSON()))) + print arr + if len(arr) != 0: + return Response(response=json.dumps(arr), status=200, - mimetype="application/json") # Real response! + mimetype="application/json") + else: + return Response(response=[], + status=200, + mimetype="application/json") - return bad_request("No Campus Found") @course_routes.route('/api/courses/help') def documentation(): From 1d9cbbfa6b1108cc5aa76f0bae838d2645127aeb Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 15 Jun 2015 18:37:08 +0300 Subject: [PATCH 5/8] getProjectsByCourseName function fix --- SE_API/ProjectRoutes.py | 87 +++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 47 deletions(-) diff --git a/SE_API/ProjectRoutes.py b/SE_API/ProjectRoutes.py index 44c2015..46d35cc 100644 --- a/SE_API/ProjectRoutes.py +++ b/SE_API/ProjectRoutes.py @@ -26,9 +26,9 @@ from SE_API.Respones_Utils import * project_routes = Blueprint("project_routes", __name__) auto = Autodoc() -@project_routes.route('/api/projects/Create//', methods=['POST']) +@project_routes.route('/api/projects/create/', methods=['POST']) @auto.doc() -def create_project(token,id): +def create_project(token): """ This call will create a new project in the DB
@@ -62,7 +62,7 @@ def create_project(token,id): #todo: check legality try: - project = Project(projectName=payload['projectName'], masterId=user.key().id(), gitRepository=payload['gitRepository'], membersId=[token]) + project = Project(projectName=payload['projectName'], courseName=payload['courseName'], masterId=user.key().id(), gitRepository=payload['gitRepository'], membersId=[token]) except Exception as e: print e return bad_request() @@ -77,62 +77,55 @@ def create_project(token,id): -@project_routes.route('/api/projects/getAll/', methods=['GET']) +@project_routes.route('/api/projects/getProjectsByCourseName/', methods=["GET"]) @auto.doc() -def get_projects(token): - """ - This Call will return an array of all projects available +def getProjectsByCourseName(name): + ''' + This Function is will Activate a user and add tha campus to it
Route Parameters
- - seToken: 'seToken' + - validation_token: 'seToken|email_suffix'

Payload
- - NONE
+ - NONE

Response
- 200 - JSON Array, Example:
- [
- { - 'title': 'JCE',
- 'email_ending': '@post.jce.ac.il',
- 'master_user_id': 123453433341, (User that created the campus)
- 'avatar_url': 'http://some.domain.com/imagefile.jpg'
- },
- ....
- {
- ...
- }req
- ]
+ 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
- 500 - Server Error - """ - if is_user_token_valid(token): - arr = [] - query = Campus.all() - for c in query.run(): - arr.append(dict(json.loads(c.to_JSON()))) - print arr - if len(arr) != 0: - return Response(response=json.dumps(arr), - status=200, - mimetype="application/json") - else: - return Response(response=[], - status=200, - mimetype="application/json") + 403 - Invalid Token + ''' + + arr = [] + query = Project.all() + query.filter("courseName = ", name) + + for p in query.run(): + arr.append(dict(json.loads(p.to_JSON()))) + print arr + if len(arr) != 0: + return Response(response=json.dumps(arr), + status=200, + mimetype="application/json") else: - return forbidden("Invalid Token") - - - -@project_routes.route('/api/Projects/', methods=['GET']) -@auto.doc() -def get_campuses(token): - pass + return Response(response=[], + status=200, + mimetype="application/json") From 7f1b912b365bfba666ce34f5eb6b7e775bf4650b Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 15 Jun 2015 18:58:03 +0300 Subject: [PATCH 6/8] added documentation --- SE_API/CampusRoutes.py | 2 -- SE_API/CourseRoutes.py | 71 +++++++++++++++++++++-------------------- SE_API/ProjectRoutes.py | 35 ++++++++++---------- 3 files changed, 53 insertions(+), 55 deletions(-) diff --git a/SE_API/CampusRoutes.py b/SE_API/CampusRoutes.py index e17bc44..8c8b02e 100644 --- a/SE_API/CampusRoutes.py +++ b/SE_API/CampusRoutes.py @@ -119,9 +119,7 @@ def get_campuses(token): ]

403 - Invalid Token
- 500 - Server Error """ - if is_user_token_valid(token): arr = [] query = Campus.all() diff --git a/SE_API/CourseRoutes.py b/SE_API/CourseRoutes.py index 95a2539..4bae4ea 100644 --- a/SE_API/CourseRoutes.py +++ b/SE_API/CourseRoutes.py @@ -31,20 +31,30 @@ auto = Autodoc() @auto.doc() def create_course(token): """ - This call will create a new campus in the DB - :param token: user seToken - Payload - { - 'courseName': self.courseName, - 'campusName': self.campusName, - 'projects': self.projects - 'startDate': self.startDate - 'endDate': self.endDate - 'taskFlag': self.taskFlag - } - - :return: - code 200 + This call will create a new course in the DB +
+ Route Parameters
+ - seToken: 'seToken' +
+
+ Payload
+ - JSON Object, Example:
+ {
+ 'courseName': 'Advance Math',
+ 'campusName': 'JCE',
+ 'startDate': '2015-14-3'
+ 'endDate': '2015-29-6'
+ 'taskFlag': 'False'
+ }
+
+
+ Response +
+ 201 - Created +
+ 400 - Bad Request +
+ 403 - Invalid token or not a lecturer """ if not request.data: return bad_request() @@ -64,6 +74,9 @@ def create_course(token): start_date = datetime.date(payload['startDate']['year'],payload['startDate']['month'],payload['startDate']['day']) end_date = datetime.date(payload['endDate']['year'],payload['endDate']['month'],payload['endDate']['day']) + 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'], startDate=start_date, endDate=end_date) @@ -76,12 +89,6 @@ def create_course(token): except Exception as e: print e - #check if and projects needs to be added - # try: - # course.projects=payload['projects'] - # except Exception: - # pass - except Exception: return bad_request() @@ -99,11 +106,11 @@ def create_course(token): @course_routes.route('/api/courses/getCourseByCampusName/', methods=["GET"]) @auto.doc() def getCourseByCampusName(name): - ''' - This Function is will Activate a user and add tha campus to it + """ + >This Call will return an array of all courses in a given campus
Route Parameters
- - validation_token: 'seToken|email_suffix' + - name: 'campus name'

Payload
@@ -115,21 +122,15 @@ def getCourseByCampusName(name): 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']
+ 'courseName': 'Advance Math',
+ 'campusName': 'JCE',
+ 'startDate': '2015-14-3'
+ 'endDate': '2015-29-6'
+ 'taskFlag': 'False'
}

- 403 - Invalid Token - ''' - + """ arr = [] query = Course.all() query.filter("campusName = ", name) diff --git a/SE_API/ProjectRoutes.py b/SE_API/ProjectRoutes.py index 46d35cc..18d2fb1 100644 --- a/SE_API/ProjectRoutes.py +++ b/SE_API/ProjectRoutes.py @@ -39,9 +39,10 @@ def create_project(token): Payload
- JSON Object, Example:
{
- 'title': 'Campus name',
- 'email_ending': '@campus.ac.com',
- 'avatar_url': 'http://location.domain.com/image.jpg'
+ 'projectName': 'Advance Math',
+ 'courseName': 'JCE',
+ 'logo_url': 'http://location.domain.com/image.jpg'
+ 'gitRepository': 'http://location.git.com/somthing'
}


@@ -49,7 +50,9 @@ def create_project(token):
201 - Created
- 403 - Invalid Token/Forbidden + 400 - Bad Request +
+ 403 - Invalid token or not a lecturer """ if not request.data: return bad_request() @@ -80,11 +83,11 @@ def create_project(token): @project_routes.route('/api/projects/getProjectsByCourseName/', methods=["GET"]) @auto.doc() def getProjectsByCourseName(name): - ''' - This Function is will Activate a user and add tha campus to it + """ + >This Call will return an array of all projects in a given course
Route Parameters
- - validation_token: 'seToken|email_suffix' + - name: 'course name'

Payload
@@ -96,20 +99,16 @@ def getProjectsByCourseName(name): 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']
+ 'projectName': 'Advance Math',
+ 'courseName': 'JCE',
+ 'grade': 98,
+ 'logo_url': 'http://location.domain.com/image.jpg',
+ 'gitRepository': 'http://location.git.com/somthing',
+ 'membersId': ['bob', 'dylan', 'quentin', 'terentino']
}

- 403 - Invalid Token - ''' + """ arr = [] query = Project.all() From 4d49e93d8cac6bad758a29a8d85ed7bbccc35a65 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 15 Jun 2015 19:06:45 +0300 Subject: [PATCH 7/8] added documentation --- SE_API/UserRoutes.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/SE_API/UserRoutes.py b/SE_API/UserRoutes.py index ddb5202..e487f2a 100644 --- a/SE_API/UserRoutes.py +++ b/SE_API/UserRoutes.py @@ -29,11 +29,11 @@ auto = Autodoc() @user_routes.route('/api/users/getUserByToken/', methods=["GET"]) @auto.doc() def getUserByToken(token): - ''' - This Function is will Activate a user and add tha campus to it + """ + >This Call will return a user by a given token
Route Parameters
- - validation_token: 'seToken|email_suffix' + - seToken: 'seToken'

Payload
@@ -45,20 +45,20 @@ def getUserByToken(token): 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']
+ 'username': 'DarkLord',
+ 'name': 'Darth Vader',
+ 'email': 'darkLord@death.planet,
+ 'isLecturer': 'True',
+ 'seToken': 'xxxxxx-xxxxx-xxxxx-xxxxxx',
+ 'avatar_url': 'http://location.git.com/somthing'
+ 'isFirstLogin': False,
+ 'campuses_id_list': ['JCA','JCB','JCC'],
+ 'classes_id_list': ['a','b','c']
}

- 403 - Invalid Token - ''' + 403 - No User Found + """ query = User.all() query.filter("seToken = ", token) From 59663af67d7ae78ff9fdfde5cad26bc9da9b30ea Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Mon, 15 Jun 2015 19:10:38 +0300 Subject: [PATCH 8/8] changed create campus dunc to send mails --- SE_API/CampusRoutes.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SE_API/CampusRoutes.py b/SE_API/CampusRoutes.py index 8c8b02e..11af4b3 100644 --- a/SE_API/CampusRoutes.py +++ b/SE_API/CampusRoutes.py @@ -20,6 +20,7 @@ from models.Campus import Campus #Validation Utils Libs from SE_API.Validation_Utils import * from SE_API.Respones_Utils import * +from SE_API.Email_Utils import * @@ -78,11 +79,10 @@ def create_campus(token): except Exception: return bad_request() - db.put(campus) - db.save - return Response(response=campus.to_JSON(), - status=201, - mimetype="application/json") + + send_create_campus_request(user.email, user.name, campus.title) + notify_se_hub_campus_request(campus, campus.title) + return ok()