Serialise template immediately after fetching

This commit changes the code in post notification endpoint to handle a
serialised template (ie a `dict`) rather than a database object.

This is the first step towards being able to cache the template and not
hit the database on every request.

There should be no functional changes here, it’s just refactoring.

There are some changes to the tests where the signature of functions
has changed.

Importing of the template schema has to be done at a function level,
otherwise Marshmallow gets weird.
This commit is contained in:
Chris Hill-Scott
2020-06-11 17:21:15 +01:00
parent 4bb37a05ec
commit 04ae715a3b
8 changed files with 134 additions and 50 deletions

View File

@@ -5,14 +5,22 @@ from app.models import LETTER_TYPE
from app.notifications.process_notifications import persist_notification
def create_letter_notification(letter_data, template, api_key, status, reply_to_text=None, billable_units=None):
def create_letter_notification(
letter_data,
template,
service,
api_key,
status,
reply_to_text=None,
billable_units=None,
):
notification = persist_notification(
template_id=template.id,
template_version=template.version,
template_postage=template.postage,
template_version=template._template['version'],
template_postage=template._template['postage'],
# we only accept addresses_with_underscores from the API (from CSV we also accept dashes, spaces etc)
recipient=PostalAddress.from_personalisation(letter_data['personalisation']).normalised,
service=template.service,
service=service,
personalisation=letter_data['personalisation'],
notification_type=LETTER_TYPE,
api_key_id=api_key.id,