commit
61bbc8d30e
6 changed files with 148 additions and 136 deletions
|
@ -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):
|
|||
]<br>
|
||||
<br>
|
||||
403 - Invalid Token<br>
|
||||
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/<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')
|
||||
def documentation():
|
||||
return auto.html()
|
||||
|
|
|
@ -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
|
||||
<span class="card-title">This call will create a new course in the DB</span>
|
||||
<br>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- JSON Object, Example: <br>
|
||||
{<br>
|
||||
'courseName': 'Advance Math',<br>
|
||||
'campusName': 'JCE',<br>
|
||||
'startDate': '2015-14-3'<br>
|
||||
'endDate': '2015-29-6'<br>
|
||||
'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:
|
||||
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/<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')
|
||||
def documentation():
|
||||
return auto.html()
|
|
@ -26,9 +26,9 @@ from SE_API.Respones_Utils import *
|
|||
project_routes = Blueprint("project_routes", __name__)
|
||||
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()
|
||||
def create_project(token,id):
|
||||
def create_project(token):
|
||||
"""
|
||||
<span class="card-title">This call will create a new project in the DB</span>
|
||||
<br>
|
||||
|
@ -39,9 +39,10 @@ def create_project(token,id):
|
|||
<b>Payload</b><br>
|
||||
- JSON Object, Example: <br>
|
||||
{<br>
|
||||
'title': 'Campus name',<br>
|
||||
'email_ending': '@campus.ac.com',<br>
|
||||
'avatar_url': 'http://location.domain.com/image.jpg'<br>
|
||||
'projectName': 'Advance Math',<br>
|
||||
'courseName': 'JCE',<br>
|
||||
'logo_url': 'http://location.domain.com/image.jpg'<br>
|
||||
'gitRepository': 'http://location.git.com/somthing'<br>
|
||||
}<br>
|
||||
<br>
|
||||
<br>
|
||||
|
@ -49,7 +50,9 @@ def create_project(token,id):
|
|||
<br>
|
||||
201 - Created
|
||||
<br>
|
||||
403 - Invalid Token/Forbidden
|
||||
400 - Bad Request
|
||||
<br>
|
||||
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,44 +80,42 @@ 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()
|
||||
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>
|
||||
<b>Route Parameters</b><br>
|
||||
- seToken: 'seToken'
|
||||
- name: 'course name'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
- NONE <br>
|
||||
- NONE
|
||||
<br>
|
||||
<br>
|
||||
<b>Response</b>
|
||||
<br>
|
||||
200 - JSON Array, Example:<br>
|
||||
[<br>
|
||||
{
|
||||
'title': 'JCE',<br>
|
||||
'email_ending': '@post.jce.ac.il',<br>
|
||||
'master_user_id': 123453433341, (User that created the campus)<br>
|
||||
'avatar_url': 'http://some.domain.com/imagefile.jpg'<br>
|
||||
},<br>
|
||||
....<br>
|
||||
200 - JSON Example:<br>
|
||||
<code>
|
||||
{<br>
|
||||
...<br>
|
||||
}req<br>
|
||||
]<br>
|
||||
'projectName': 'Advance Math',<br>
|
||||
'courseName': 'JCE',<br>
|
||||
'grade': 98,<br>
|
||||
'logo_url': 'http://location.domain.com/image.jpg',<br>
|
||||
'gitRepository': 'http://location.git.com/somthing',<br>
|
||||
'membersId': ['bob', 'dylan', 'quentin', 'terentino']<br>
|
||||
}
|
||||
</code>
|
||||
<br>
|
||||
403 - Invalid Token<br>
|
||||
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())))
|
||||
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),
|
||||
|
@ -124,15 +125,6 @@ def get_projects(token):
|
|||
return Response(response=[],
|
||||
status=200,
|
||||
mimetype="application/json")
|
||||
else:
|
||||
return forbidden("Invalid Token")
|
||||
|
||||
|
||||
|
||||
@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"])
|
||||
@auto.doc()
|
||||
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>
|
||||
<b>Route Parameters</b><br>
|
||||
- validation_token: 'seToken|email_suffix'
|
||||
- seToken: 'seToken'
|
||||
<br>
|
||||
<br>
|
||||
<b>Payload</b><br>
|
||||
|
@ -45,20 +45,20 @@ def getUserByToken(token):
|
|||
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>
|
||||
'username': 'DarkLord',<br>
|
||||
'name': 'Darth Vader',<br>
|
||||
'email': 'darkLord@death.planet,<br>
|
||||
'isLecturer': 'True',<br>
|
||||
'seToken': 'xxxxxx-xxxxx-xxxxx-xxxxxx',<br>
|
||||
'avatar_url': 'http://location.git.com/somthing'<br>
|
||||
'isFirstLogin': False,<br>
|
||||
'campuses_id_list': ['JCA','JCB','JCC'],<br>
|
||||
'classes_id_list': ['a','b','c']<br>
|
||||
}
|
||||
</code>
|
||||
<br>
|
||||
403 - Invalid Token
|
||||
'''
|
||||
403 - No User Found
|
||||
"""
|
||||
query = User.all()
|
||||
query.filter("seToken = ", token)
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue