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

@@ -527,8 +527,24 @@ def resume_service(service_id):
@service_blueprint.route('/<uuid:service_id>/notifications/templates_usage/monthly', methods=['GET'])
def get_monthly_template_usage(service_id):
try:
data = dao_fetch_monthly_historical_usage_by_template_for_service(service_id)
return jsonify(stats=[i.serialize() for i in data]), 200
data = dao_fetch_monthly_historical_usage_by_template_for_service(
service_id,
int(request.args.get('year', 'NaN'))
)
stats = list()
for i in data:
stats.append(
{
'template_id': str(i.template_id),
'name': i.name,
'month': i.month,
'year': i.year,
'count': i.count
}
)
return jsonify(stats=stats), 200
except ValueError:
raise InvalidRequest('Year must be a number', status_code=400)