mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-27 11:19:56 -04:00
make inbound sms page respect data retention
also, it should default to last 7 days, not last 6 days. also change count_inbound_sms to have the days passed in, so that it's more explicit at the endpoint that we only return 7 days regardless of your service's data retention
This commit is contained in:
@@ -55,11 +55,10 @@ def dao_get_paginated_inbound_sms_for_service_for_public_api(
|
||||
).items
|
||||
|
||||
|
||||
def dao_count_inbound_sms_for_service(service_id):
|
||||
start_date = midnight_n_days_ago(6)
|
||||
def dao_count_inbound_sms_for_service(service_id, limit_days):
|
||||
return InboundSms.query.filter(
|
||||
InboundSms.service_id == service_id,
|
||||
InboundSms.created_at >= start_date
|
||||
InboundSms.created_at >= midnight_n_days_ago(limit_days)
|
||||
).count()
|
||||
|
||||
|
||||
@@ -126,10 +125,11 @@ def dao_get_inbound_sms_by_id(service_id, inbound_id):
|
||||
|
||||
def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(
|
||||
service_id,
|
||||
page
|
||||
page,
|
||||
limit_days
|
||||
):
|
||||
"""
|
||||
This query starts from inbound_sms and joins on to itself to find the most recent row for each user_number
|
||||
This query starts from inbound_sms and joins on to itself to find the most recent row for each user_number.
|
||||
|
||||
Equivalent sql:
|
||||
|
||||
@@ -146,7 +146,6 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(
|
||||
ORDER BY t1.created_at DESC;
|
||||
LIMIT 50 OFFSET :page
|
||||
"""
|
||||
start_date = midnight_n_days_ago(6)
|
||||
t2 = aliased(InboundSms)
|
||||
q = db.session.query(
|
||||
InboundSms
|
||||
@@ -160,7 +159,7 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(
|
||||
).filter(
|
||||
t2.id == None, # noqa
|
||||
InboundSms.service_id == service_id,
|
||||
InboundSms.created_at >= start_date
|
||||
InboundSms.created_at >= midnight_n_days_ago(limit_days)
|
||||
).order_by(
|
||||
InboundSms.created_at.desc()
|
||||
)
|
||||
|
||||
@@ -12,6 +12,7 @@ from app.dao.inbound_sms_dao import (
|
||||
dao_get_inbound_sms_by_id,
|
||||
dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service
|
||||
)
|
||||
from app.dao.service_data_retention_dao import fetch_service_data_retention_by_notification_type
|
||||
from app.errors import register_errors
|
||||
from app.schema_validation import validate
|
||||
|
||||
@@ -55,9 +56,12 @@ def get_inbound_sms_for_service(service_id):
|
||||
def get_most_recent_inbound_sms_for_service(service_id):
|
||||
# used on the service inbox page
|
||||
page = request.args.get('page', 1)
|
||||
# get most recent message for each user for service
|
||||
|
||||
results = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(service_id, int(page))
|
||||
inbound_data_retention = fetch_service_data_retention_by_notification_type(service_id, 'sms')
|
||||
limit_days = inbound_data_retention.days_of_retention if inbound_data_retention else 7
|
||||
|
||||
# get most recent message for each user for service
|
||||
results = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(service_id, int(page), limit_days)
|
||||
return jsonify(
|
||||
data=[row.serialize() for row in results.items],
|
||||
has_next=results.has_next
|
||||
@@ -66,7 +70,8 @@ def get_most_recent_inbound_sms_for_service(service_id):
|
||||
|
||||
@inbound_sms.route('/summary')
|
||||
def get_inbound_sms_summary_for_service(service_id):
|
||||
count = dao_count_inbound_sms_for_service(service_id)
|
||||
# this is for the dashboard, so always limit to 7 days, even if they have a longer data retention
|
||||
count = dao_count_inbound_sms_for_service(service_id, limit_days=7)
|
||||
most_recent = dao_get_inbound_sms_for_service(service_id, limit=1)
|
||||
|
||||
return jsonify(
|
||||
|
||||
Reference in New Issue
Block a user