mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 00:41:35 -05:00
Template rest api skeleton added.
This commit is contained in:
34
app/template/rest.py
Normal file
34
app/template/rest.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from flask import (jsonify, request)
|
||||
from sqlalchemy.exc import DataError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from app.dao.templates_dao import get_model_templates
|
||||
from app.dao.services_dao import get_model_services
|
||||
from app.schemas import (template_schema, templates_schema)
|
||||
from app import db
|
||||
|
||||
from flask import (jsonify, request)
|
||||
from sqlalchemy.exc import DataError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from . import template
|
||||
from app import db
|
||||
|
||||
|
||||
# I am going to keep these for admin like operations
|
||||
# Permissions should restrict who can access this endpoint
|
||||
# TODO auth to be added.
|
||||
@template.route('/<int:template_id>', methods=['GET'])
|
||||
@template.route('/', methods=['GET'])
|
||||
def get_template(template_id=None):
|
||||
try:
|
||||
templates = get_model_templates(template_id=template_id)
|
||||
except DataError:
|
||||
return jsonify(result="error", message="Invalid template id"), 400
|
||||
except NoResultFound:
|
||||
return jsonify(result="error", message="Template not found"), 404
|
||||
if isinstance(templates, list):
|
||||
data, errors = templates_schema.dump(templates)
|
||||
else:
|
||||
data, errors = template_schema.dump(templates)
|
||||
if errors:
|
||||
return jsonify(result="error", message=str(errors))
|
||||
return jsonify(data=data)
|
||||
Reference in New Issue
Block a user