mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
Merge pull request #762 from alphagov/v2-get-notification-by-reference
V2 get notification by reference
This commit is contained in:
@@ -248,6 +248,15 @@ 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)
|
||||
|
||||
|
||||
@@ -18,12 +18,23 @@ def get_notification_by_id(id):
|
||||
@notification_blueprint.route("", methods=['GET'])
|
||||
def get_notifications():
|
||||
_data = request.args.to_dict(flat=False)
|
||||
|
||||
# flat=False makes everything a list, but we only ever allow one value for "older_than"
|
||||
if 'older_than' in _data:
|
||||
# flat=False makes everything a list, but we only ever allow one value for "older_than"
|
||||
_data['older_than'] = _data['older_than'][0]
|
||||
|
||||
# and client reference
|
||||
if 'client_reference' in _data:
|
||||
_data['client_reference'] = _data['client_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,
|
||||
|
||||
@@ -78,6 +78,7 @@ get_notifications_request = {
|
||||
"description": "schema for query parameters allowed when getting list of notifications",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"client_reference": {"type": "string"},
|
||||
"status": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
||||
Reference in New Issue
Block a user