Add endpoint to get inbound by id

This commit is contained in:
Imdad Ahad
2017-06-06 17:12:21 +01:00
parent 23a501af16
commit ee488d416a
2 changed files with 48 additions and 1 deletions

View File

@@ -1,11 +1,19 @@
import uuid
from flask import (
Blueprint,
jsonify,
request
)
from werkzeug.exceptions import abort
from notifications_utils.recipients import validate_and_format_phone_number
from app.dao.inbound_sms_dao import dao_get_inbound_sms_for_service, dao_count_inbound_sms_for_service
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
)
from app.errors import register_errors
inbound_sms = Blueprint(
@@ -40,3 +48,16 @@ def get_inbound_sms_summary_for_service(service_id):
count=count,
most_recent=most_recent[0].created_at.isoformat() if most_recent else None
)
@inbound_sms.route('/<inbound_sms_id>', methods=['GET'])
def get_inbound_by_id(service_id, inbound_sms_id):
# TODO: Add JSON Schema here
try:
validated_uuid = uuid.UUID(inbound_sms_id)
except (ValueError, AttributeError):
abort(400)
inbound_sms = dao_get_inbound_sms_by_id(validated_uuid)
return jsonify(inbound_sms.serialize()), 200