__author__ = 'Aran' from flask import Blueprint import json from GithubAPI.GithubAPI import GitHubAPI_Keys from google.appengine.ext import db import requests import datetime from flask import Flask, request, render_template, redirect, abort, Response from flask.ext.github import GitHub from flask.ext.cors import CORS, cross_origin from flask.ext.autodoc import Autodoc # DB Models from models.Project import Project #Validation Utils Libs from SE_API.Validation_Utils import * from SE_API.Respones_Utils import * project_routes = Blueprint("project_routes", __name__) auto = Autodoc() @project_routes.route('/api/projects/Create//', methods=['POST']) @auto.doc() def create_project(token,id): """ This call will create a new project in the DB
Route Parameters
- seToken: 'seToken'

Payload
- JSON Object, Example:
{
'title': 'Campus name',
'email_ending': '@campus.ac.com',
'avatar_url': 'http://location.domain.com/image.jpg'
}


Response
201 - Created
403 - Invalid Token/Forbidden """ 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: project = Project(projectName=payload['projectName'], masterId=user.key().id(), gitRepository=payload['gitRepository'], membersId=[token]) except Exception as e: print e return bad_request() db.put(project) db.save return Response(response=project.to_JSON(), status=201, mimetype="application/json") @project_routes.route('/api/projects/getAll/', methods=['GET']) @auto.doc() def get_projects(token): """ This Call will return an array of all projects available
Route Parameters
- seToken: 'seToken'

Payload
- 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
]

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") else: return forbidden("Invalid Token") @project_routes.route('/api/Projects/', methods=['GET']) @auto.doc() def get_campuses(token): pass @project_routes.route('/api/projects/help') def documentation(): return auto.html()