mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-04 08:10:00 -04:00
Create platform-stats blueprint
Created a platform-stats blueprint and moved the new platform stats endpoint to the new blueprint (it was previously in the service blueprint). Since the original platform stats route and the new platform stats route are now in different blueprints, their view functions can have the same name without any issues.
This commit is contained in:
0
app/platform_stats/__init__.py
Normal file
0
app/platform_stats/__init__.py
Normal file
24
app/platform_stats/rest.py
Normal file
24
app/platform_stats/rest.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from datetime import datetime
|
||||
|
||||
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.service.statistics import format_admin_stats
|
||||
|
||||
platform_stats_blueprint = Blueprint('platform_stats', __name__)
|
||||
|
||||
register_errors(platform_stats_blueprint)
|
||||
|
||||
|
||||
@platform_stats_blueprint.route('')
|
||||
def get_new_platform_stats():
|
||||
# If start and end date are not set, we are expecting today's stats.
|
||||
today = str(datetime.utcnow().date())
|
||||
|
||||
start_date = datetime.strptime(request.args.get('start_date', today), '%Y-%m-%d').date()
|
||||
end_date = datetime.strptime(request.args.get('end_date', today), '%Y-%m-%d').date()
|
||||
data = fetch_aggregate_stats_by_date_range_for_all_services(start_date=start_date, end_date=end_date)
|
||||
stats = format_admin_stats(data)
|
||||
|
||||
return jsonify(stats)
|
||||
Reference in New Issue
Block a user