commit
61bbc8d30e
6 changed files with 148 additions and 136 deletions
|
@ -20,6 +20,7 @@ from models.Campus import Campus
|
||||||
#Validation Utils Libs
|
#Validation Utils Libs
|
||||||
from SE_API.Validation_Utils import *
|
from SE_API.Validation_Utils import *
|
||||||
from SE_API.Respones_Utils import *
|
from SE_API.Respones_Utils import *
|
||||||
|
from SE_API.Email_Utils import *
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,11 +79,10 @@ def create_campus(token):
|
||||||
except Exception:
|
except Exception:
|
||||||
return bad_request()
|
return bad_request()
|
||||||
|
|
||||||
db.put(campus)
|
|
||||||
db.save
|
send_create_campus_request(user.email, user.name, campus.title)
|
||||||
return Response(response=campus.to_JSON(),
|
notify_se_hub_campus_request(campus, campus.title)
|
||||||
status=201,
|
return ok()
|
||||||
mimetype="application/json")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,9 +119,7 @@ def get_campuses(token):
|
||||||
]<br>
|
]<br>
|
||||||
<br>
|
<br>
|
||||||
403 - Invalid Token<br>
|
403 - Invalid Token<br>
|
||||||
500 - Server Error
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if is_user_token_valid(token):
|
if is_user_token_valid(token):
|
||||||
arr = []
|
arr = []
|
||||||
query = Campus.all()
|
query = Campus.all()
|
||||||
|
@ -141,51 +139,6 @@ def get_campuses(token):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@campus_routes.route('/api/campuses/getCampusId/<string:name>', methods=["GET"])
|
|
||||||
@auto.doc()
|
|
||||||
def getCampusId(name):
|
|
||||||
'''
|
|
||||||
<span class="card-title">This Function is will Activate a user and add tha campus to it</span>
|
|
||||||
<br>
|
|
||||||
<b>Route Parameters</b><br>
|
|
||||||
- validation_token: 'seToken|email_suffix'
|
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
<b>Payload</b><br>
|
|
||||||
- NONE
|
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
<b>Response</b>
|
|
||||||
<br>
|
|
||||||
200 - JSON Example:<br>
|
|
||||||
<code>
|
|
||||||
{<br>
|
|
||||||
'username' : 'github_username',<br>
|
|
||||||
'name' : 'Bob Dylan',<br>
|
|
||||||
'email' : 'email@domain.com',<br>
|
|
||||||
'isLecturer' : true,<br>
|
|
||||||
'seToken' : 'dds2d-sfvvsf-qqq-fdf33-sfaa',<br>
|
|
||||||
'avatar_url' : 'http://location.domain.com/image.jpg',<br>
|
|
||||||
'isFirstLogin' : false,<br>
|
|
||||||
'campuses_id_list': ['22314','243512',...,'356'],<br>
|
|
||||||
'classes_id_list': ['22314','243512',...,'356']<br>
|
|
||||||
}
|
|
||||||
</code>
|
|
||||||
<br>
|
|
||||||
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')
|
@campus_routes.route('/api/campuses/help')
|
||||||
def documentation():
|
def documentation():
|
||||||
return auto.html()
|
return auto.html()
|
||||||
|
|
|
@ -31,43 +31,63 @@ auto = Autodoc()
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def create_course(token):
|
def create_course(token):
|
||||||
"""
|
"""
|
||||||
This call will create a new campus in the DB
|
<span class="card-title">This call will create a new course in the DB</span>
|
||||||
:param token: user seToken
|
<br>
|
||||||
Payload
|
<b>Route Parameters</b><br>
|
||||||
{
|
- seToken: 'seToken'
|
||||||
'courseName': self.courseName,
|
<br>
|
||||||
'campusName': self.campusName,
|
<br>
|
||||||
'projects': self.projects
|
<b>Payload</b><br>
|
||||||
'startDate': self.startDate
|
- JSON Object, Example: <br>
|
||||||
'endDate': self.endDate
|
{<br>
|
||||||
'taskFlag': self.taskFlag
|
'courseName': 'Advance Math',<br>
|
||||||
}
|
'campusName': 'JCE',<br>
|
||||||
|
'startDate': '2015-14-3'<br>
|
||||||
:return:
|
'endDate': '2015-29-6'<br>
|
||||||
code 200
|
'taskFlag': 'False'<br>
|
||||||
|
}<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<b>Response</b>
|
||||||
|
<br>
|
||||||
|
201 - Created
|
||||||
|
<br>
|
||||||
|
400 - Bad Request
|
||||||
|
<br>
|
||||||
|
403 - Invalid token or not a lecturer
|
||||||
"""
|
"""
|
||||||
if not request.data:
|
if not request.data:
|
||||||
return bad_request()
|
return bad_request()
|
||||||
payload = json.loads(request.data)
|
|
||||||
if not is_lecturer(token): #todo: change to lecturer id
|
if not is_lecturer(token): #todo: change to lecturer id
|
||||||
return forbidden("Invalid token or not a lecturer!")
|
return forbidden("Invalid token or not a lecturer!")
|
||||||
|
|
||||||
user = get_user_by_token(token)
|
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:
|
try:
|
||||||
start_date = datetime.date(payload['startDate']['year'],payload['startDate']['month'],payload['startDate']['day'])
|
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'])
|
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'],
|
course = Course(courseName=payload['courseName'], campusName=payload['campusName'],
|
||||||
startDate=start_date, endDate=end_date)
|
startDate=start_date, endDate=end_date)
|
||||||
|
|
||||||
|
#check if name already exists
|
||||||
try:
|
try:
|
||||||
course.projects=payload['projects']
|
query = Course.all()
|
||||||
except Exception:
|
query.filter("courseName = ", payload['courseName'])
|
||||||
pass
|
for c in query.run(limit=1):
|
||||||
|
return forbidden("Campus with same name already exists")
|
||||||
|
except Exception as e:
|
||||||
|
print e
|
||||||
|
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -83,6 +103,51 @@ def create_course(token):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@course_routes.route('/api/courses/getCourseByCampusName/<string:name>', methods=["GET"])
|
||||||
|
@auto.doc()
|
||||||
|
def getCourseByCampusName(name):
|
||||||
|
"""
|
||||||
|
<span class="card-title">>This Call will return an array of all courses in a given campus</span>
|
||||||
|
<br>
|
||||||
|
<b>Route Parameters</b><br>
|
||||||
|
- name: 'campus name'
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<b>Payload</b><br>
|
||||||
|
- NONE
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<b>Response</b>
|
||||||
|
<br>
|
||||||
|
200 - JSON Example:<br>
|
||||||
|
<code>
|
||||||
|
{<br>
|
||||||
|
'courseName': 'Advance Math',<br>
|
||||||
|
'campusName': 'JCE',<br>
|
||||||
|
'startDate': '2015-14-3'<br>
|
||||||
|
'endDate': '2015-29-6'<br>
|
||||||
|
'taskFlag': 'False'<br>
|
||||||
|
}
|
||||||
|
</code>
|
||||||
|
<br>
|
||||||
|
"""
|
||||||
|
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')
|
@course_routes.route('/api/courses/help')
|
||||||
def documentation():
|
def documentation():
|
||||||
return auto.html()
|
return auto.html()
|
|
@ -26,9 +26,9 @@ from SE_API.Respones_Utils import *
|
||||||
project_routes = Blueprint("project_routes", __name__)
|
project_routes = Blueprint("project_routes", __name__)
|
||||||
auto = Autodoc()
|
auto = Autodoc()
|
||||||
|
|
||||||
@project_routes.route('/api/projects/Create/<string:token>/<string:id>', methods=['POST'])
|
@project_routes.route('/api/projects/create/<string:token>', methods=['POST'])
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def create_project(token,id):
|
def create_project(token):
|
||||||
"""
|
"""
|
||||||
<span class="card-title">This call will create a new project in the DB</span>
|
<span class="card-title">This call will create a new project in the DB</span>
|
||||||
<br>
|
<br>
|
||||||
|
@ -39,9 +39,10 @@ def create_project(token,id):
|
||||||
<b>Payload</b><br>
|
<b>Payload</b><br>
|
||||||
- JSON Object, Example: <br>
|
- JSON Object, Example: <br>
|
||||||
{<br>
|
{<br>
|
||||||
'title': 'Campus name',<br>
|
'projectName': 'Advance Math',<br>
|
||||||
'email_ending': '@campus.ac.com',<br>
|
'courseName': 'JCE',<br>
|
||||||
'avatar_url': 'http://location.domain.com/image.jpg'<br>
|
'logo_url': 'http://location.domain.com/image.jpg'<br>
|
||||||
|
'gitRepository': 'http://location.git.com/somthing'<br>
|
||||||
}<br>
|
}<br>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
|
@ -49,7 +50,9 @@ def create_project(token,id):
|
||||||
<br>
|
<br>
|
||||||
201 - Created
|
201 - Created
|
||||||
<br>
|
<br>
|
||||||
403 - Invalid Token/Forbidden
|
400 - Bad Request
|
||||||
|
<br>
|
||||||
|
403 - Invalid token or not a lecturer
|
||||||
"""
|
"""
|
||||||
if not request.data:
|
if not request.data:
|
||||||
return bad_request()
|
return bad_request()
|
||||||
|
@ -62,7 +65,7 @@ def create_project(token,id):
|
||||||
#todo: check legality
|
#todo: check legality
|
||||||
|
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
print e
|
print e
|
||||||
return bad_request()
|
return bad_request()
|
||||||
|
@ -77,62 +80,51 @@ def create_project(token,id):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@project_routes.route('/api/projects/getAll/<string:token>', methods=['GET'])
|
@project_routes.route('/api/projects/getProjectsByCourseName/<string:name>', methods=["GET"])
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def get_projects(token):
|
def getProjectsByCourseName(name):
|
||||||
"""
|
"""
|
||||||
<span class="card-title">This Call will return an array of all projects available</span>
|
<span class="card-title">>This Call will return an array of all projects in a given course</span>
|
||||||
<br>
|
<br>
|
||||||
<b>Route Parameters</b><br>
|
<b>Route Parameters</b><br>
|
||||||
- seToken: 'seToken'
|
- name: 'course name'
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<b>Payload</b><br>
|
<b>Payload</b><br>
|
||||||
- NONE <br>
|
- NONE
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<b>Response</b>
|
<b>Response</b>
|
||||||
<br>
|
<br>
|
||||||
200 - JSON Array, Example:<br>
|
200 - JSON Example:<br>
|
||||||
[<br>
|
<code>
|
||||||
{
|
{<br>
|
||||||
'title': 'JCE',<br>
|
'projectName': 'Advance Math',<br>
|
||||||
'email_ending': '@post.jce.ac.il',<br>
|
'courseName': 'JCE',<br>
|
||||||
'master_user_id': 123453433341, (User that created the campus)<br>
|
'grade': 98,<br>
|
||||||
'avatar_url': 'http://some.domain.com/imagefile.jpg'<br>
|
'logo_url': 'http://location.domain.com/image.jpg',<br>
|
||||||
},<br>
|
'gitRepository': 'http://location.git.com/somthing',<br>
|
||||||
....<br>
|
'membersId': ['bob', 'dylan', 'quentin', 'terentino']<br>
|
||||||
{<br>
|
}
|
||||||
...<br>
|
</code>
|
||||||
}req<br>
|
|
||||||
]<br>
|
|
||||||
<br>
|
<br>
|
||||||
403 - Invalid Token<br>
|
|
||||||
500 - Server Error
|
|
||||||
"""
|
"""
|
||||||
if is_user_token_valid(token):
|
|
||||||
arr = []
|
arr = []
|
||||||
query = Campus.all()
|
query = Project.all()
|
||||||
for c in query.run():
|
query.filter("courseName = ", name)
|
||||||
arr.append(dict(json.loads(c.to_JSON())))
|
|
||||||
print arr
|
for p in query.run():
|
||||||
if len(arr) != 0:
|
arr.append(dict(json.loads(p.to_JSON())))
|
||||||
return Response(response=json.dumps(arr),
|
print arr
|
||||||
status=200,
|
if len(arr) != 0:
|
||||||
mimetype="application/json")
|
return Response(response=json.dumps(arr),
|
||||||
else:
|
status=200,
|
||||||
return Response(response=[],
|
mimetype="application/json")
|
||||||
status=200,
|
|
||||||
mimetype="application/json")
|
|
||||||
else:
|
else:
|
||||||
return forbidden("Invalid Token")
|
return Response(response=[],
|
||||||
|
status=200,
|
||||||
|
mimetype="application/json")
|
||||||
|
|
||||||
@project_routes.route('/api/Projects/<string:token>', methods=['GET'])
|
|
||||||
@auto.doc()
|
|
||||||
def get_campuses(token):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,11 @@ auto = Autodoc()
|
||||||
@user_routes.route('/api/users/getUserByToken/<string:token>', methods=["GET"])
|
@user_routes.route('/api/users/getUserByToken/<string:token>', methods=["GET"])
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def getUserByToken(token):
|
def getUserByToken(token):
|
||||||
'''
|
"""
|
||||||
<span class="card-title">This Function is will Activate a user and add tha campus to it</span>
|
<span class="card-title">>This Call will return a user by a given token</span>
|
||||||
<br>
|
<br>
|
||||||
<b>Route Parameters</b><br>
|
<b>Route Parameters</b><br>
|
||||||
- validation_token: 'seToken|email_suffix'
|
- seToken: 'seToken'
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<b>Payload</b><br>
|
<b>Payload</b><br>
|
||||||
|
@ -45,20 +45,20 @@ def getUserByToken(token):
|
||||||
200 - JSON Example:<br>
|
200 - JSON Example:<br>
|
||||||
<code>
|
<code>
|
||||||
{<br>
|
{<br>
|
||||||
'username' : 'github_username',<br>
|
'username': 'DarkLord',<br>
|
||||||
'name' : 'Bob Dylan',<br>
|
'name': 'Darth Vader',<br>
|
||||||
'email' : 'email@domain.com',<br>
|
'email': 'darkLord@death.planet,<br>
|
||||||
'isLecturer' : true,<br>
|
'isLecturer': 'True',<br>
|
||||||
'seToken' : 'dds2d-sfvvsf-qqq-fdf33-sfaa',<br>
|
'seToken': 'xxxxxx-xxxxx-xxxxx-xxxxxx',<br>
|
||||||
'avatar_url' : 'http://location.domain.com/image.jpg',<br>
|
'avatar_url': 'http://location.git.com/somthing'<br>
|
||||||
'isFirstLogin' : false,<br>
|
'isFirstLogin': False,<br>
|
||||||
'campuses_id_list': ['22314','243512',...,'356'],<br>
|
'campuses_id_list': ['JCA','JCB','JCC'],<br>
|
||||||
'classes_id_list': ['22314','243512',...,'356']<br>
|
'classes_id_list': ['a','b','c']<br>
|
||||||
}
|
}
|
||||||
</code>
|
</code>
|
||||||
<br>
|
<br>
|
||||||
403 - Invalid Token
|
403 - No User Found
|
||||||
'''
|
"""
|
||||||
query = User.all()
|
query = User.all()
|
||||||
query.filter("seToken = ", token)
|
query.filter("seToken = ", token)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Course(db.Model):
|
||||||
courseName = db.StringProperty(required=True)
|
courseName = db.StringProperty(required=True)
|
||||||
campusName = db.StringProperty(required=True)
|
campusName = db.StringProperty(required=True)
|
||||||
master_id = db.IntegerProperty(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)
|
startDate = db.DateProperty(required=True)
|
||||||
endDate = db.DateProperty(required=True)
|
endDate = db.DateProperty(required=True)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class Course(db.Model):
|
||||||
data = {'courseName' : self.courseName,
|
data = {'courseName' : self.courseName,
|
||||||
'campusName' : self.campusName,
|
'campusName' : self.campusName,
|
||||||
'master_id' : self.master_id,
|
'master_id' : self.master_id,
|
||||||
'projects' : self.projects,
|
# 'projects' : self.projects,
|
||||||
'startDate' : {
|
'startDate' : {
|
||||||
'year': self.startDate.year,
|
'year': self.startDate.year,
|
||||||
'month': self.startDate.month,
|
'month': self.startDate.month,
|
||||||
|
|
|
@ -5,6 +5,7 @@ from google.appengine.ext import db
|
||||||
|
|
||||||
class Project(db.Model):
|
class Project(db.Model):
|
||||||
projectName = db.StringProperty(required=True)
|
projectName = db.StringProperty(required=True)
|
||||||
|
courseName = db.StringProperty(required=True)
|
||||||
master_id = db.IntegerProperty(required=True)
|
master_id = db.IntegerProperty(required=True)
|
||||||
grade = db.IntegerProperty(required=True, default=0)
|
grade = db.IntegerProperty(required=True, default=0)
|
||||||
logo_url = db.StringProperty(required=False)
|
logo_url = db.StringProperty(required=False)
|
||||||
|
@ -13,6 +14,7 @@ class Project(db.Model):
|
||||||
|
|
||||||
def to_JSON(self):
|
def to_JSON(self):
|
||||||
data = {'projectName' : self.projectName,
|
data = {'projectName' : self.projectName,
|
||||||
|
'courseName' : self.courseName,
|
||||||
'master_id' : self.master_id,
|
'master_id' : self.master_id,
|
||||||
'grade' : self.grade,
|
'grade' : self.grade,
|
||||||
'logo_url' : self.logo_url,
|
'logo_url' : self.logo_url,
|
||||||
|
|
Loading…
Reference in a new issue