Template rest api skeleton added.

This commit is contained in:
Nicholas Staples
2016-01-13 11:04:13 +00:00
parent 81cd230a79
commit dad0fff4ba
11 changed files with 252 additions and 1 deletions

31
app/dao/templates_dao.py Normal file
View File

@@ -0,0 +1,31 @@
import json
from datetime import datetime
from sqlalchemy.orm import load_only
from . import DAOException
from app import db
from app.models import (Template, Service)
def save_model_template(template, update_dict=None):
if update_dict:
Template.query.filter_by(id=template.id).update(update_dict)
else:
db.session.add(template)
db.session.commit()
def delete_model_template(template):
db.session.delete(template)
db.session.commit()
def get_model_templates(template_id=None, service_id=None):
# TODO need better mapping from function params to sql query.
if template_id and service_id:
return Template.query.filter_by(
id=template_id, service=Service.get(service_id)).one()
elif template_id:
return Template.query.filter_by(id=template_id).one()
elif service_id:
return Template.query.filter_by(service=Service.get(service_id)).one()
return Template.query.all()