mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 14:29:25 -04:00
Adds a POST version of get inbound messages by phone number. Allows us to POST the search so the phone number is hidden
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from flask import (
|
||||
Blueprint,
|
||||
jsonify,
|
||||
request
|
||||
)
|
||||
request,
|
||||
current_app, json)
|
||||
from jsonschema import ValidationError
|
||||
|
||||
from notifications_utils.recipients import validate_and_format_phone_number
|
||||
|
||||
@@ -12,6 +13,9 @@ from app.dao.inbound_sms_dao import (
|
||||
dao_get_inbound_sms_by_id
|
||||
)
|
||||
from app.errors import register_errors
|
||||
from app.schema_validation import validate
|
||||
|
||||
from app.inbound_sms.inbound_sms_schemas import get_inbound_sms_for_service_schema
|
||||
|
||||
inbound_sms = Blueprint(
|
||||
'inbound_sms',
|
||||
@@ -22,18 +26,25 @@ inbound_sms = Blueprint(
|
||||
register_errors(inbound_sms)
|
||||
|
||||
|
||||
@inbound_sms.route('')
|
||||
@inbound_sms.route('', methods=['POST', 'GET'])
|
||||
def get_inbound_sms_for_service(service_id):
|
||||
limit = request.args.get('limit')
|
||||
user_number = request.args.get('user_number')
|
||||
|
||||
if user_number:
|
||||
# we use this to normalise to an international phone number
|
||||
user_number = validate_and_format_phone_number(user_number, international=True)
|
||||
if request.method == 'GET':
|
||||
limit = request.args.get('limit')
|
||||
user_number = request.args.get('user_number')
|
||||
|
||||
results = dao_get_inbound_sms_for_service(service_id, limit, user_number)
|
||||
if user_number:
|
||||
# we use this to normalise to an international phone number
|
||||
user_number = validate_and_format_phone_number(user_number, international=True)
|
||||
|
||||
return jsonify(data=[row.serialize() for row in results])
|
||||
results = dao_get_inbound_sms_for_service(service_id, limit, user_number)
|
||||
|
||||
return jsonify(data=[row.serialize() for row in results])
|
||||
else:
|
||||
form = validate(request.get_json(), get_inbound_sms_for_service_schema)
|
||||
results = dao_get_inbound_sms_for_service(service_id, form.get('limit'), form.get('phone_number'))
|
||||
|
||||
return jsonify(data=[row.serialize() for row in results])
|
||||
|
||||
|
||||
@inbound_sms.route('/summary')
|
||||
@@ -49,6 +60,6 @@ def get_inbound_sms_summary_for_service(service_id):
|
||||
|
||||
@inbound_sms.route('/<uuid:inbound_sms_id>', methods=['GET'])
|
||||
def get_inbound_by_id(service_id, inbound_sms_id):
|
||||
inbound_sms = dao_get_inbound_sms_by_id(service_id, inbound_sms_id)
|
||||
message = dao_get_inbound_sms_by_id(service_id, inbound_sms_id)
|
||||
|
||||
return jsonify(inbound_sms.serialize()), 200
|
||||
return jsonify(message.serialize()), 200
|
||||
|
||||
Reference in New Issue
Block a user