diff --git a/app/service/rest.py b/app/service/rest.py index 8975aa9df..d2e383817 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -27,6 +27,7 @@ from app.dao.organisation_dao import dao_get_organisation_by_service_id from app.dao.service_data_retention_dao import ( fetch_service_data_retention, fetch_service_data_retention_by_id, + fetch_service_data_retention_by_notification_type, insert_service_data_retention, update_service_data_retention, ) @@ -759,6 +760,12 @@ def get_data_retention_for_service(service_id): return jsonify([data_retention.serialize() for data_retention in data_retention_list]), 200 +@service_blueprint.route('//data-retention/notification-type/', methods=['GET']) +def get_data_retention_for_service_notification_type(service_id, notification_type): + data_retention = fetch_service_data_retention_by_notification_type(service_id, notification_type) + return jsonify(data_retention.serialize() if data_retention else {}), 200 + + @service_blueprint.route('//data-retention/', methods=['GET']) def get_data_retention_for_service_by_id(service_id, data_retention_id): data_retention = fetch_service_data_retention_by_id(service_id, data_retention_id) diff --git a/tests/app/service/test_service_data_retention_rest.py b/tests/app/service/test_service_data_retention_rest.py index da58d597e..7797f62cb 100644 --- a/tests/app/service/test_service_data_retention_rest.py +++ b/tests/app/service/test_service_data_retention_rest.py @@ -35,6 +35,15 @@ def test_get_service_data_retention_returns_empty_list(client, sample_service): assert len(json.loads(response.get_data(as_text=True))) == 0 +def test_get_data_retention_for_service_notification_type(client, sample_service): + data_retention = create_service_data_retention(service_id=sample_service.id) + response = client.get('/service/{}/data-retention/notification-type/{}'.format(sample_service.id, 'sms'), + headers=[('Content-Type', 'application/json'), create_authorization_header()], + ) + assert response.status_code == 200 + assert json.loads(response.get_data(as_text=True)) == data_retention.serialize() + + def test_get_service_data_retention_by_id(client, sample_service): sms_data_retention = create_service_data_retention(service_id=sample_service.id) create_service_data_retention(service_id=sample_service.id, notification_type='email',