diff --git a/SE_API/CampusRoutes.py b/SE_API/CampusRoutes.py index a93c187..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() @@ -119,9 +119,7 @@ def get_campuses(token): ]

403 - Invalid Token
- 500 - Server Error """ - if is_user_token_valid(token): arr = [] query = Campus.all() @@ -141,51 +139,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() diff --git a/SE_API/CourseRoutes.py b/SE_API/CourseRoutes.py index 6b76f3b..4bae4ea 100644 --- a/SE_API/CourseRoutes.py +++ b/SE_API/CourseRoutes.py @@ -31,43 +31,63 @@ 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() - 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: 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) + #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 except Exception: @@ -83,6 +103,51 @@ def create_course(token): +@course_routes.route('/api/courses/getCourseByCampusName/', methods=["GET"]) +@auto.doc() +def getCourseByCampusName(name): + """ + >This Call will return an array of all courses in a given campus +
+ Route Parameters
+ - name: 'campus name' +
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ + {
+ 'courseName': 'Advance Math',
+ 'campusName': 'JCE',
+ 'startDate': '2015-14-3'
+ 'endDate': '2015-29-6'
+ 'taskFlag': 'False'
+ } +
+
+ """ + arr = [] + query = Course.all() + query.filter("campusName = ", name) + + 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") + + @course_routes.route('/api/courses/help') def documentation(): return auto.html() \ No newline at end of file diff --git a/SE_API/ProjectRoutes.py b/SE_API/ProjectRoutes.py index 44c2015..18d2fb1 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
@@ -39,9 +39,10 @@ def create_project(token,id): 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,id):
201 - Created
- 403 - Invalid Token/Forbidden + 400 - Bad Request +
+ 403 - Invalid token or not a lecturer """ if not request.data: return bad_request() @@ -62,7 +65,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 +80,51 @@ 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): +def getProjectsByCourseName(name): """ - This Call will return an array of all projects available + >This Call will return an array of all projects in a given course
Route Parameters
- - seToken: 'seToken' + - name: 'course name'

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:
+ + {
+ '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
- 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") + + 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") 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) 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,