- Implemented persist_notification and send_notification_to_queue in the process_notifications module

- Not sure I want to create a new classmethod on Notifications to create from v2 request. Will take another look at that.
This commit is contained in:
Rebecca Law
2016-10-27 17:34:54 +01:00
parent c2eecdae36
commit 6e4bad135a
6 changed files with 158 additions and 24 deletions

View File

@@ -54,3 +54,14 @@ post_sms_response = {
},
"required": ["id", "content", "uri", "template"]
}
def create_post_sms_response_from_notification(notification, content):
return {"id": notification.id,
"reference": None, # not yet implemented
"content": content,
"uri": "v2/notifications/{}".format(notification.id),
"template": {"id": notification.template_id,
"version": notification.template_version,
"uri": "v2/templates/{}".format(notification.template_id)}
}

View File

@@ -1,9 +1,9 @@
from flask import request
from flask import request, jsonify
from app import api_user
from app.dao import services_dao, templates_dao
from app.models import SMS_TYPE
from app.notifications.process_notifications import create_content_for_notification
from app.notifications.process_notifications import create_content_for_notification, persist_notification, \
send_notification_to_queue
from app.notifications.validators import (check_service_message_limit,
check_template_is_for_notification_type,
check_template_is_active,
@@ -11,7 +11,8 @@ from app.notifications.validators import (check_service_message_limit,
check_sms_content_char_count)
from app.schema_validation import validate
from app.v2.notifications import notification_blueprint
from app.v2.notifications.notification_schemas import post_sms_request
from app.v2.notifications.notification_schemas import (post_sms_request,
create_post_sms_response_from_notification)
@notification_blueprint.route('/sms', methods=['POST'])
@@ -34,9 +35,17 @@ def post_sms_notification():
check_sms_content_char_count(template_with_content.replaced_content_count)
# persist notification
# send sms to provider queue for research mode queue
# return post_sms_response schema
return "post_sms_response schema", 201
notification = persist_notification(template_id=template.id,
template_version=template.version,
recipient=form['phone_number'],
service_id=service.id,
personalisation=form.get('personalisation', None),
notification_type=SMS_TYPE,
api_key_id=api_user.id,
key_type=api_user.key_type)
send_notification_to_queue(notification, service.research_mode)
resp = create_post_sms_response_from_notification(notification, template_with_content.content)
return jsonify(resp), 201
@notification_blueprint.route('/email', methods=['POST'])