Changed db queries to use one, which throws NoResultFound exception, this exception is dealt with in our error handlers.

Now a lot of the if none checks can be removed.
This commit is contained in:
Rebecca Law
2016-03-11 12:39:55 +00:00
parent 209244ff19
commit e055590b07
19 changed files with 66 additions and 112 deletions

View File

@@ -18,7 +18,7 @@ from app.dao.services_dao import (
)
from app.schemas import template_schema
template = Blueprint('template', __name__, url_prefix='/service/<service_id>/template')
template = Blueprint('template', __name__, url_prefix='/service/<uuid:service_id>/template')
from app.errors import register_errors
@@ -28,8 +28,6 @@ register_errors(template)
@template.route('', methods=['POST'])
def create_template(service_id):
fetched_service = dao_fetch_service_by_id(service_id=service_id)
if not fetched_service:
return jsonify(result="error", message="Service not found"), 404
new_template, errors = template_schema.load(request.get_json())
if errors:
@@ -52,8 +50,6 @@ def create_template(service_id):
@template.route('/<int:template_id>', methods=['POST'])
def update_template(service_id, template_id):
fetched_template = dao_get_template_by_id_and_service_id(template_id=template_id, service_id=service_id)
if not fetched_template:
return jsonify(result="error", message="Template not found"), 404
current_data = dict(template_schema.dump(fetched_template).data.items())
current_data.update(request.get_json())
@@ -77,11 +73,8 @@ def get_all_templates_for_service(service_id):
@template.route('/<int:template_id>', methods=['GET'])
def get_template_by_id_and_service_id(service_id, template_id):
fetched_template = dao_get_template_by_id_and_service_id(template_id=template_id, service_id=service_id)
if fetched_template:
data, errors = template_schema.dump(fetched_template)
return jsonify(data=data)
else:
return jsonify(result="error", message="Template not found"), 404
data, errors = template_schema.dump(fetched_template)
return jsonify(data=data)
def _strip_html(content):