mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-14 02:48:01 -04:00
Update /service/{}/notifications to look for a "to" query string, if it exists call the search notifications_by_to_field method.
This commit is contained in:
@@ -492,6 +492,7 @@ class NotificationsFilterSchema(ma.Schema):
|
||||
include_from_test_key = fields.Boolean(required=False)
|
||||
older_than = fields.UUID(required=False)
|
||||
format_for_csv = fields.String()
|
||||
to = fields.String()
|
||||
|
||||
@pre_load
|
||||
def handle_multidict(self, in_data):
|
||||
|
||||
@@ -242,6 +242,8 @@ def get_service_history(service_id):
|
||||
@service_blueprint.route('/<uuid:service_id>/notifications', methods=['GET'])
|
||||
def get_all_notifications_for_service(service_id):
|
||||
data = notifications_filter_schema.load(request.args).data
|
||||
if data.get("to", None):
|
||||
return search_for_notification_by_to_field(service_id, request.query_string.decode())
|
||||
page = data['page'] if 'page' in data else 1
|
||||
page_size = data['page_size'] if 'page_size' in data else current_app.config.get('PAGE_SIZE')
|
||||
limit_days = data.get('limit_days')
|
||||
@@ -271,8 +273,8 @@ def get_all_notifications_for_service(service_id):
|
||||
), 200
|
||||
|
||||
|
||||
@service_blueprint.route('/<uuid:service_id>/notification/<search_term>', methods=['GET'])
|
||||
def search_for_notification_by_to_field(service_id, search_term):
|
||||
search_term = search_term.replace('to=', '')
|
||||
results = notifications_dao.dao_get_notifications_by_to_field(service_id, search_term)
|
||||
return jsonify(
|
||||
notifications=notification_with_template_schema.dump(results, many=True).data), 200
|
||||
|
||||
@@ -1621,7 +1621,7 @@ def test_search_for_notification_by_to_field(client, notify_db, notify_db_sessio
|
||||
to_field="+447700900855")
|
||||
notification2 = create_sample_notification(notify_db, notify_db_session, to_field="jack@gmail.com")
|
||||
|
||||
response = client.get('/service/{}/notification/{}'.format(notification1.service_id, "jack@gmail.com"),
|
||||
response = client.get('/service/{}/notifications?to={}'.format(notification1.service_id, "jack@gmail.com"),
|
||||
headers=[create_authorization_header()])
|
||||
assert response.status_code == 200
|
||||
result = json.loads(response.get_data(as_text=True))
|
||||
@@ -1635,7 +1635,7 @@ def test_search_for_notification_by_to_field_return_empty_list_if_there_is_no_ma
|
||||
to_field="+447700900855")
|
||||
notification2 = create_sample_notification(notify_db, notify_db_session, to_field="jack@gmail.com")
|
||||
|
||||
response = client.get('/service/{}/notification/{}'.format(notification1.service_id, "+447700900800"),
|
||||
response = client.get('/service/{}/notifications?to={}'.format(notification1.service_id, "+447700900800"),
|
||||
headers=[create_authorization_header()])
|
||||
assert response.status_code == 200
|
||||
assert len(json.loads(response.get_data(as_text=True))["notifications"]) == 0
|
||||
@@ -1651,7 +1651,7 @@ def test_search_for_notification_by_to_field_return_multiple_matches(
|
||||
to_field="+44770 0900 855")
|
||||
notification4 = create_sample_notification(notify_db, notify_db_session, to_field="jack@gmail.com")
|
||||
|
||||
response = client.get('/service/{}/notification/{}'.format(notification1.service_id, "+447700900855"),
|
||||
response = client.get('/service/{}/notifications?to={}'.format(notification1.service_id, "+447700900855"),
|
||||
headers=[create_authorization_header()])
|
||||
assert response.status_code == 200
|
||||
result = json.loads(response.get_data(as_text=True))
|
||||
|
||||
Reference in New Issue
Block a user