Add limit_days argument to notification statistics endpoint

Allows getting notification counts for a given number of days to
support services with custom data retention periods (admin dashboard
page should still display counts for the last 7 days, while the
notifications page displays all stored notifications).
This commit is contained in:
Alexey Bezhan
2018-08-13 16:34:04 +01:00
parent 3e51b69df6
commit 5f2724c429
3 changed files with 18 additions and 11 deletions

View File

@@ -165,7 +165,11 @@ def get_service_by_id(service_id):
@service_blueprint.route('/<uuid:service_id>/statistics')
def get_service_notification_statistics(service_id):
return jsonify(data=get_service_statistics(service_id, request.args.get('today_only') == 'True'))
return jsonify(data=get_service_statistics(
service_id,
request.args.get('today_only') == 'True',
int(request.args.get('limit_days', 7))
))
@service_blueprint.route('', methods=['POST'])
@@ -423,10 +427,13 @@ def get_detailed_service(service_id, today_only=False):
return detailed_service_schema.dump(service).data
def get_service_statistics(service_id, today_only):
def get_service_statistics(service_id, today_only, limit_days=7):
# today_only flag is used by the send page to work out if the service will exceed their daily usage by sending a job
stats_fn = dao_fetch_todays_stats_for_service if today_only else dao_fetch_stats_for_service
stats = stats_fn(service_id)
if today_only:
stats = dao_fetch_todays_stats_for_service(service_id)
else:
stats = dao_fetch_stats_for_service(service_id, limit_days=limit_days)
return statistics.format_statistics(stats)