mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Added a date range filter for the get all services end point.
When the start_date and end_date query argruments exists in the request, the query will return the results from the NotificationHistory table for the given date range. We will need to check the performance of this query, but this will only be used by the platform admin page.
This commit is contained in:
@@ -263,3 +263,31 @@ def dao_fetch_todays_stats_for_all_services(include_from_test_key=True):
|
||||
query = query.filter(Notification.key_type != KEY_TYPE_TEST)
|
||||
|
||||
return query
|
||||
|
||||
|
||||
@statsd(namespace='dao')
|
||||
def fetch_stats_by_date_range_for_all_services(start_date, end_date, include_from_test_key=True):
|
||||
query = db.session.query(
|
||||
NotificationHistory.notification_type,
|
||||
NotificationHistory.status,
|
||||
NotificationHistory.service_id,
|
||||
func.count(NotificationHistory.id).label('count')
|
||||
).select_from(
|
||||
Service
|
||||
).join(
|
||||
NotificationHistory
|
||||
).filter(
|
||||
func.date(NotificationHistory.created_at) >= start_date,
|
||||
func.date(NotificationHistory.created_at) <= end_date
|
||||
).group_by(
|
||||
NotificationHistory.notification_type,
|
||||
NotificationHistory.status,
|
||||
NotificationHistory.service_id
|
||||
).order_by(
|
||||
NotificationHistory.service_id
|
||||
)
|
||||
|
||||
if not include_from_test_key:
|
||||
query = query.filter(NotificationHistory.key_type != KEY_TYPE_TEST)
|
||||
|
||||
return query
|
||||
|
||||
Reference in New Issue
Block a user