diff --git a/app/service/rest.py b/app/service/rest.py index 89a47cb63..385dfeb8b 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -1,7 +1,7 @@ import itertools from datetime import datetime -from flask import Blueprint, current_app, jsonify, request, url_for +from flask import Blueprint, current_app, jsonify, request from notifications_utils.letter_timings import ( letter_can_be_cancelled, too_late_to_cancel_letter, @@ -148,6 +148,7 @@ from app.user.users_schema import post_set_permissions_schema from app.utils import ( DATE_FORMAT, DATETIME_FORMAT_NO_TIMEZONE, + get_prev_next_pagination_links, midnight_n_days_ago, pagination_links, ) @@ -463,16 +464,6 @@ def get_all_notifications_for_service(service_id): error_out=False # False so that if there are no results, it doesn't end in aborting with a 404 ) - def get_prev_next_pagination_links(current_page, next_page_exists, endpoint, **kwargs): - if 'page' in kwargs: - kwargs.pop('page', None) - links = {} - if page > 1: - links['prev'] = url_for(endpoint, page=page - 1, **kwargs) - if next_page_exists: - links['next'] = url_for(endpoint, page=page + 1, **kwargs) - return links - return jsonify( notifications=notifications, page_size=page_size, diff --git a/app/utils.py b/app/utils.py index d2cf06181..a2e8f8eb8 100644 --- a/app/utils.py +++ b/app/utils.py @@ -29,6 +29,17 @@ def pagination_links(pagination, endpoint, **kwargs): return links +def get_prev_next_pagination_links(current_page, next_page_exists, endpoint, **kwargs): + if 'page' in kwargs: + kwargs.pop('page', None) + links = {} + if current_page > 1: + links['prev'] = url_for(endpoint, page=current_page - 1, **kwargs) + if next_page_exists: + links['next'] = url_for(endpoint, page=current_page + 1, **kwargs) + return links + + def url_with_token(data, url, config, base_url=None): from notifications_utils.url_safe_token import generate_token token = generate_token(data, config['SECRET_KEY'], config['DANGEROUS_SALT'])