Add schema and validate platform stats requests

Added a schema to check that the start_date and end_date arguments are
both in the date format.
This commit is contained in:
Katie Smith
2018-06-29 15:54:32 +01:00
parent cbb9f71e61
commit b4654781be
3 changed files with 32 additions and 5 deletions

View File

@@ -0,0 +1,10 @@
platform_stats_request = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "platform stats request schema",
"type": "object",
"title": "Platform stats request",
"properties": {
"start_date": {"type": ["string", "null"], "format": "date"},
"end_date": {"type": ["string", "null"], "format": "date"},
}
}

View File

@@ -4,7 +4,9 @@ from flask import Blueprint, jsonify, request
from app.dao.notifications_dao import fetch_aggregate_stats_by_date_range_for_all_services
from app.errors import register_errors
from app.platform_stats.platform_stats_schema import platform_stats_request
from app.service.statistics import format_admin_stats
from app.schema_validation import validate
platform_stats_blueprint = Blueprint('platform_stats', __name__)
@@ -12,7 +14,10 @@ register_errors(platform_stats_blueprint)
@platform_stats_blueprint.route('')
def get_new_platform_stats():
def get_platform_stats():
if request.args:
validate(request.args, platform_stats_request)
# If start and end date are not set, we are expecting today's stats.
today = str(datetime.utcnow().date())