mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-09 10:53:55 -04:00
New endpoint to search by "to" field of the notification.
The query ignores case and spaces.
This commit is contained in:
@@ -456,3 +456,10 @@ def dao_update_notifications_sent_to_dvla(job_id, provider):
|
||||
{'status': NOTIFICATION_SENDING, "sent_by": provider, "sent_at": now, "updated_at": now})
|
||||
|
||||
return updated_count
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_notifications_by_to_field(service_id, search_term):
|
||||
return Notification.query.filter(
|
||||
Notification.service_id == service_id,
|
||||
func.replace(func.lower(Notification.to), " ", "") == search_term.lower().replace(" ", "")).all()
|
||||
|
||||
@@ -271,6 +271,13 @@ 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):
|
||||
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
|
||||
|
||||
|
||||
@service_blueprint.route('/<uuid:service_id>/notifications/monthly', methods=['GET'])
|
||||
def get_monthly_notification_stats(service_id):
|
||||
service = dao_fetch_service_by_id(service_id)
|
||||
|
||||
Reference in New Issue
Block a user