Add Template name to response and filter by year

The template name should be returned for the response and the user will
pick a year, so ths adds those two features to the
notifications/templates_usage/monthly endpoint and added some tests to
test the functionality.
This commit is contained in:
Richard Chapman
2017-11-15 15:55:00 +00:00
parent 618c7676e6
commit 1e4850b70f
7 changed files with 157 additions and 31 deletions

View File

@@ -30,11 +30,16 @@ def insert_or_update_stats_for_template(template_id, month, year, count):
@statsd(namespace="dao")
def dao_get_template_usage_stats_by_service(service_id):
def dao_get_template_usage_stats_by_service(service_id, year):
return db.session.query(
StatsTemplateUsageByMonth
StatsTemplateUsageByMonth.template_id,
Template.name,
StatsTemplateUsageByMonth.month,
StatsTemplateUsageByMonth.year,
StatsTemplateUsageByMonth.count
).join(
Template, StatsTemplateUsageByMonth.template_id == Template.id
).filter(
Template.service_id == service_id
Template.service_id == service_id,
StatsTemplateUsageByMonth.year == year
).all()