API: Added Campus Model - And A new API Call

This commit is contained in:
Sagi Dayan 2015-06-10 13:12:59 +03:00
parent 9b887c0599
commit a37ef482ca
3 changed files with 81 additions and 5 deletions

View file

@ -14,6 +14,10 @@ from flask.ext.autodoc import Autodoc
# DB Models
from models.User import User
from models.Campus import Campus
#Validation Utils Libs
from SE_API.Validation_Utils import *
@ -98,10 +102,7 @@ def oauth(oauth_token):
u.put()
return cookieMonster(u.seToken)
if user_data["name"] == "":
tempName = ";"
else:
tempName = user_data["name"]
tempName = ";"
if user_data["email"] == "":
for email in userEmails:
@ -110,13 +111,52 @@ def oauth(oauth_token):
else:
tempEmail = user_data["email"]
user = User(username=user_data["login"], name=tempName, avatar_url=user_data["avatar_url"], email=tempEmail, isLecturer=False, accsessToken=oauth_token, seToken=str(uuid.uuid4()))
db.put(user)
db.save
return cookieMonster(user.seToken)
@app.route('/api/Campuses/<string:token>', methods=['GET'])
@auto.doc()
def get_campuses(token):
"""
This Call will return an array of all Campuses available
:param token: user seToken
:return:
code 200:
[{'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'
},
....
{
...
}
]
code 403: Forbidden - Invalid Token
code 500: internal server error
"""
if is_user_token_valid(token):
arr = []
query = User.all()
for c in query.run():
arr.append(c.to_JSON)
if len(arr) != 0:
return Response(response=json.dumps([]),
status=200,
mimetype="application/json")
else:
return Response(response=[],
status=200,
mimetype="application/json")
else:
return Response(response=json.dumps({'message': 'Invalid Token'}),
status=403,
mimetype="application/json")
@app.route('/login')

View file

@ -0,0 +1,11 @@
__author__ = 'sagi'
from google.appengine.ext import db
from models.User import User
def is_user_token_valid(token):
query = User.all()
query.filter("seToken = ", token)
for u in query.run():
return True
return False

25
models/Campus.py Normal file
View file

@ -0,0 +1,25 @@
__author__ = 'sagi'
import json
from google.appengine.ext import db
class Campus(db.Model):
title = db.StringProperty(required=True)
avatar_url = db.StringProperty(required=True)
email_ending = db.StringProperty(required=True)
master_user_id = db.IntegerProperty(required=True)
def to_JSON(self):
dick = {'title': self.username,
'email_ending': self.email_ending,
'master_user_id': self.master_user_id,
'avatar_url': self.avatar_url
}
return json.dumps(dick)
"""
DEBUG Script - To create a campus:
"""