Remove the call to the db after the notification has committed.

After the commit we issue two calls to the db to get service and get notification. This is because after the commit the ORM wants to ensure that the data model objects are the latest.

So far this is just a proof of concept, but the letter flow needs to be updated and we should be able to get rid of research mode. And it needs some tidy up.
This commit is contained in:
Rebecca Law
2020-06-16 14:33:53 +01:00
parent eec2c2859e
commit 21a1b8e8bd
4 changed files with 140 additions and 41 deletions

View File

@@ -44,3 +44,66 @@ def __create_notification_response(notification, url_root, scheduled_for):
},
"scheduled_for": scheduled_for if scheduled_for else None
}
# test detaching notification
def create_post_sms_response_from_notification_detached(
notification_id, client_reference, template_id, template_version, service_id,
content, from_number, url_root, scheduled_for
):
resp = __create_notification_response_detached(
notification_id, client_reference, template_id, template_version, service_id, url_root, scheduled_for
)
resp['content'] = {
'from_number': from_number,
'body': content
}
return resp
def create_post_email_response_from_notification_detached(
notification_id, client_reference, template_id, template_version, service_id, content, subject, email_from,
url_root, scheduled_for):
resp = __create_notification_response_detached(
notification_id, client_reference, template_id, template_version, service_id, url_root, scheduled_for
)
resp['content'] = {
"from_email": email_from,
"body": content,
"subject": subject
}
return resp
def create_post_letter_response_from_notification_detached(
notification_id, client_reference, template_id, template_version, service_id,
content, subject, url_root, scheduled_for
):
resp = __create_notification_response_detached(
notification_id, client_reference, template_id, template_version, service_id, url_root, scheduled_for
)
resp['content'] = {
"body": content,
"subject": subject
}
return resp
def __create_notification_response_detached(
notification_id, client_reference, template_id, template_version, service_id, url_root, scheduled_for
):
return {
"id": notification_id,
"reference": client_reference,
"uri": "{}v2/notifications/{}".format(url_root, str(notification_id)),
'template': {
"id": template_id,
"version": template_version,
"uri": "{}services/{}/templates/{}".format(
url_root,
str(service_id),
str(template_id)
)
},
"scheduled_for": scheduled_for if scheduled_for else None
}