Merge branch 'master' into secure-endpoints

Conflicts:
	app/__init__.py
This commit is contained in:
Rebecca Law
2017-03-17 10:24:12 +00:00
14 changed files with 468 additions and 12 deletions

View File

@@ -0,0 +1,7 @@
from flask import Blueprint
from app.v2.errors import register_errors
template_blueprint = Blueprint("v2_template", __name__, url_prefix='/v2/template')
register_errors(template_blueprint)

View File

@@ -0,0 +1,30 @@
import uuid
from flask import jsonify, request
from jsonschema.exceptions import ValidationError
from werkzeug.exceptions import abort
from app import api_user
from app.dao import templates_dao
from app.schema_validation import validate
from app.v2.template import template_blueprint
from app.v2.template.template_schemas import get_template_by_id_request
@template_blueprint.route("/<template_id>", methods=['GET'])
@template_blueprint.route("/<template_id>/version/<int:version>", methods=['GET'])
def get_template_by_id(template_id, version=None):
try:
_data = {}
_data['id'] = template_id
if version:
_data['version'] = version
data = validate(_data, get_template_by_id_request)
except ValueError or AttributeError:
abort(404)
template = templates_dao.dao_get_template_by_id_and_service_id(
template_id, api_user.service_id, data.get('version'))
return jsonify(template.serialize()), 200

View File

@@ -0,0 +1,41 @@
from app.models import TEMPLATE_TYPES
from app.schema_validation.definitions import uuid
get_template_by_id_request = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "schema for parameters allowed when getting template by id",
"type": "object",
"properties": {
"id": uuid,
"version": {"type": ["integer", "null"], "minimum": 1}
},
"required": ["id"],
"additionalProperties": False,
}
get_template_by_id_response = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "GET template by id schema response",
"type": "object",
"title": "reponse v2/template",
"properties": {
"id": uuid,
"type": {"enum": TEMPLATE_TYPES},
"created_at": {
"format": "date-time",
"type": "string",
"description": "Date+time created"
},
"updated_at": {
"format": "date-time",
"type": ["string", "null"],
"description": "Date+time updated"
},
"created_by": {"type": "string"},
"version": {"type": "integer"},
"body": {"type": "string"},
"subject": {"type": ["string", "null"]}
},
"required": ["id", "type", "created_at", "updated_at", "version", "created_by", "body"]
}