mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Merge pull request #1790 from alphagov/update-paginated-inbound-sms-method
Update inbound sms method
This commit is contained in:
@@ -32,7 +32,23 @@ def dao_get_inbound_sms_for_service(service_id, limit=None, user_number=None):
|
||||
return q.all()
|
||||
|
||||
|
||||
def dao_get_paginated_inbound_sms_for_service(
|
||||
def dao_get_paginated_inbound_sms_for_service(service_id, user_number=None, page=1):
|
||||
q = InboundSms.query.filter(
|
||||
InboundSms.service_id == service_id
|
||||
).order_by(
|
||||
InboundSms.created_at.desc()
|
||||
)
|
||||
|
||||
if user_number:
|
||||
q = q.filter(InboundSms.user_number == user_number)
|
||||
|
||||
return q.paginate(
|
||||
page=page,
|
||||
per_page=current_app.config['PAGE_SIZE']
|
||||
)
|
||||
|
||||
|
||||
def dao_get_paginated_inbound_sms_for_service_for_public_api(
|
||||
service_id,
|
||||
older_than=None,
|
||||
page_size=None
|
||||
|
||||
@@ -9,7 +9,8 @@ from notifications_utils.recipients import try_validate_and_format_phone_number
|
||||
from app.dao.inbound_sms_dao import (
|
||||
dao_get_inbound_sms_for_service,
|
||||
dao_count_inbound_sms_for_service,
|
||||
dao_get_inbound_sms_by_id
|
||||
dao_get_inbound_sms_by_id,
|
||||
dao_get_paginated_inbound_sms_for_service
|
||||
)
|
||||
from app.errors import register_errors
|
||||
from app.schema_validation import validate
|
||||
@@ -41,15 +42,22 @@ def post_query_inbound_sms_for_service(service_id):
|
||||
@inbound_sms.route('', methods=['GET'])
|
||||
def get_inbound_sms_for_service(service_id):
|
||||
limit = request.args.get('limit')
|
||||
page = request.args.get('page')
|
||||
user_number = request.args.get('user_number')
|
||||
|
||||
if user_number:
|
||||
# we use this to normalise to an international phone number - but this may fail if it's an alphanumeric
|
||||
user_number = try_validate_and_format_phone_number(user_number, international=True)
|
||||
|
||||
results = dao_get_inbound_sms_for_service(service_id, limit, user_number)
|
||||
|
||||
return jsonify(data=[row.serialize() for row in results])
|
||||
if not page:
|
||||
results = dao_get_inbound_sms_for_service(service_id, limit, user_number)
|
||||
return jsonify(data=[row.serialize() for row in results])
|
||||
else:
|
||||
results = dao_get_paginated_inbound_sms_for_service(service_id, user_number, int(page))
|
||||
return jsonify(
|
||||
data=[row.serialize() for row in results.items],
|
||||
has_next=results.has_next
|
||||
)
|
||||
|
||||
|
||||
@inbound_sms.route('/summary')
|
||||
|
||||
@@ -11,7 +11,7 @@ from app.v2.inbound_sms.inbound_sms_schemas import get_inbound_sms_request
|
||||
def get_inbound_sms():
|
||||
data = validate(request.args.to_dict(), get_inbound_sms_request)
|
||||
|
||||
paginated_inbound_sms = inbound_sms_dao.dao_get_paginated_inbound_sms_for_service(
|
||||
paginated_inbound_sms = inbound_sms_dao.dao_get_paginated_inbound_sms_for_service_for_public_api(
|
||||
authenticated_service.id,
|
||||
older_than=data.get('older_than', None),
|
||||
page_size=current_app.config.get('API_PAGE_SIZE')
|
||||
|
||||
Reference in New Issue
Block a user