2016-03-08 16:34:03 +00:00
|
|
|
from flask import (
|
|
|
|
|
Blueprint,
|
|
|
|
|
jsonify,
|
2016-04-20 10:33:41 +01:00
|
|
|
request
|
2016-03-08 16:34:03 +00:00
|
|
|
)
|
|
|
|
|
|
2016-04-27 10:58:08 +01:00
|
|
|
from app.dao.notifications_dao import dao_get_notification_statistics_for_service
|
2016-03-08 16:34:03 +00:00
|
|
|
from app.schemas import notifications_statistics_schema
|
|
|
|
|
|
|
|
|
|
notifications_statistics = Blueprint(
|
|
|
|
|
'notifications-statistics',
|
|
|
|
|
__name__, url_prefix='/service/<service_id>/notifications-statistics'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
from app.errors import register_errors
|
|
|
|
|
|
|
|
|
|
register_errors(notifications_statistics)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@notifications_statistics.route('', methods=['GET'])
|
2016-04-19 16:34:17 +01:00
|
|
|
def get_all_notification_statistics_for_service(service_id):
|
|
|
|
|
|
|
|
|
|
if request.args.get('limit_days'):
|
|
|
|
|
try:
|
2016-04-27 10:58:08 +01:00
|
|
|
statistics = dao_get_notification_statistics_for_service(
|
2016-04-19 16:34:17 +01:00
|
|
|
service_id=service_id,
|
|
|
|
|
limit_days=int(request.args['limit_days'])
|
|
|
|
|
)
|
|
|
|
|
except ValueError as e:
|
|
|
|
|
error = '{} is not an integer'.format(request.args['limit_days'])
|
|
|
|
|
current_app.logger.error(error)
|
|
|
|
|
return jsonify(result="error", message={'limit_days': [error]}), 400
|
|
|
|
|
else:
|
|
|
|
|
statistics = dao_get_notification_statistics_for_service(service_id=service_id)
|
|
|
|
|
|
|
|
|
|
data, errors = notifications_statistics_schema.dump(statistics, many=True)
|
2016-03-08 16:34:03 +00:00
|
|
|
return jsonify(data=data)
|