Retrieve notifications by reference:

* Use get_notifications instead (references may not be unique)
This commit is contained in:
Imdad Ahad
2016-12-12 18:04:20 +00:00
parent 4f9b295a5b
commit 431ec8acad
3 changed files with 10 additions and 20 deletions

View File

@@ -248,15 +248,6 @@ def get_notification_by_id(notification_id):
return Notification.query.filter_by(id=notification_id).first()
@statsd(namespace="dao")
def get_notification_by_reference(service_id, reference, key_type):
filter_dict = {'service_id': service_id, 'client_reference': reference}
if key_type:
filter_dict['key_type'] = key_type
return Notification.query.filter_by(**filter_dict).options(joinedload('template_history')).one()
def get_notifications(filter_dict=None):
return _filter_query(Notification.query, filter_dict=filter_dict)
@@ -272,7 +263,8 @@ def get_notifications_for_service(
personalisation=False,
include_jobs=False,
include_from_test_key=False,
older_than=None
older_than=None,
client_reference=None
):
if page_size is None:
page_size = current_app.config['PAGE_SIZE']
@@ -296,6 +288,9 @@ def get_notifications_for_service(
elif not include_from_test_key:
filters.append(Notification.key_type != KEY_TYPE_TEST)
if client_reference is not None:
filters.append(Notification.client_reference == client_reference)
query = Notification.query.filter(*filters)
query = _filter_query(query, filter_dict)
if personalisation:

View File

@@ -24,23 +24,18 @@ def get_notifications():
_data['older_than'] = _data['older_than'][0]
# and client reference
if 'client_reference' in _data:
_data['client_reference'] = _data['client_reference'][0]
if 'reference' in _data:
_data['reference'] = _data['reference'][0]
data = validate(_data, get_notifications_request)
if data.get('client_reference'):
notification = notifications_dao.get_notification_by_reference(
str(api_user.service_id), data.get('client_reference'), key_type=None
)
return jsonify(notification.serialize()), 200
paginated_notifications = notifications_dao.get_notifications_for_service(
str(api_user.service_id),
filter_dict=data,
key_type=api_user.key_type,
personalisation=True,
older_than=data.get('older_than')
older_than=data.get('older_than'),
client_reference=data.get('reference')
)
def _build_links(notifications):

View File

@@ -78,7 +78,7 @@ get_notifications_request = {
"description": "schema for query parameters allowed when getting list of notifications",
"type": "object",
"properties": {
"client_reference": {"type": "string"},
"reference": {"type": "string"},
"status": {
"type": "array",
"items": {