'detailed' flag on GET /service/<uuid>

if passed in, returns the service object with additional statistics
dictionary, which will be used in the admin app to populate dashboard
components. A new schema has been created for this to avoid clashing/
causing confusion with the existing schema, which is already used
for PUT/POST as well, and this schema can be easily tailored to
reduce ambiguity and lazy-loading
This commit is contained in:
Leo Hemsted
2016-07-18 12:03:44 +01:00
parent a355f3e544
commit 2d1babf2bb
5 changed files with 131 additions and 8 deletions

View File

@@ -1,15 +1,13 @@
import uuid
from app import db
from app.models import Service
from sqlalchemy import asc
from sqlalchemy import asc, func
from sqlalchemy.orm import joinedload
from app import db
from app.dao.dao_utils import (
transactional,
version_class
)
from app.models import (
NotificationStatistics,
TemplateStatistics,
@@ -135,3 +133,16 @@ def delete_service_and_all_associated_db_objects(service):
db.session.commit()
list(map(db.session.delete, users))
db.session.commit()
def dao_fetch_stats_for_service(service_id):
return db.session.query(
Notification.notification_type,
Notification.status,
func.count(Notification.id).label('count')
).filter(
Notification.service_id == service_id
).group_by(
Notification.notification_type,
Notification.status,
).all()