commit
1c05b8aea1
4 changed files with 66 additions and 7 deletions
|
@ -53,13 +53,25 @@ def create_campus(token):
|
||||||
"""
|
"""
|
||||||
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)
|
#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:
|
try:
|
||||||
campus = Campus(title=payload['title'], email_ending=payload['email_ending'], master_user_id=user.key().id(), avatar_url=payload['avatar_url'])
|
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/<string:token>', methods=['GET'])
|
@campus_routes.route('/api/campuses/getAll/<string:token>', methods=['GET'])
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def get_campuses(token):
|
def get_campuses(token):
|
||||||
"""
|
"""
|
||||||
|
@ -129,6 +141,50 @@ 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():
|
||||||
|
|
|
@ -77,7 +77,7 @@ def create_project(token,id):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@project_routes.route('/api/projects/get/<string:token>', methods=['GET'])
|
@project_routes.route('/api/projects/getAll/<string:token>', methods=['GET'])
|
||||||
@auto.doc()
|
@auto.doc()
|
||||||
def get_projects(token):
|
def get_projects(token):
|
||||||
"""
|
"""
|
||||||
|
@ -136,6 +136,7 @@ def get_campuses(token):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@project_routes.route('/api/projects/help')
|
@project_routes.route('/api/projects/help')
|
||||||
def documentation():
|
def documentation():
|
||||||
return auto.html()
|
return auto.html()
|
|
@ -6,6 +6,7 @@ from google.appengine.ext import db
|
||||||
class Course(db.Model):
|
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)
|
||||||
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)
|
||||||
|
@ -13,6 +14,7 @@ class Course(db.Model):
|
||||||
def to_JSON(self):
|
def to_JSON(self):
|
||||||
data = {'courseName' : self.courseName,
|
data = {'courseName' : self.courseName,
|
||||||
'campusName' : self.campusName,
|
'campusName' : self.campusName,
|
||||||
|
'master_id' : self.master_id,
|
||||||
'projects' : self.projects,
|
'projects' : self.projects,
|
||||||
'startDate' : {
|
'startDate' : {
|
||||||
'year': self.startDate.year,
|
'year': self.startDate.year,
|
||||||
|
|
|
@ -5,7 +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)
|
||||||
masterId = 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)
|
||||||
gitRepository = db.StringProperty(required=True)
|
gitRepository = db.StringProperty(required=True)
|
||||||
|
@ -13,7 +13,7 @@ class Project(db.Model):
|
||||||
|
|
||||||
def to_JSON(self):
|
def to_JSON(self):
|
||||||
data = {'projectName' : self.projectName,
|
data = {'projectName' : self.projectName,
|
||||||
'masterId' : self.masterId,
|
'master_id' : self.master_id,
|
||||||
'grade' : self.grade,
|
'grade' : self.grade,
|
||||||
'logo_url' : self.logo_url,
|
'logo_url' : self.logo_url,
|
||||||
'gitRepository' : self.gitRepository,
|
'gitRepository' : self.gitRepository,
|
||||||
|
|
Loading…
Reference in a new issue