mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Refactor to re-use existing contract-dependent method
This commit is contained in:
@@ -260,9 +260,10 @@ def send_notification(notification_type):
|
||||
status_code=400
|
||||
)
|
||||
|
||||
notification_id = create_uuid()
|
||||
notification.update({"template_version": template.version})
|
||||
|
||||
if not _simulated_recipient(notification['to'], notification_type):
|
||||
notification_id = create_uuid()
|
||||
notification.update({"template_version": template.version})
|
||||
persist_notification(
|
||||
service,
|
||||
notification_id,
|
||||
@@ -273,16 +274,12 @@ def send_notification(notification_type):
|
||||
api_user.key_type
|
||||
)
|
||||
|
||||
return jsonify(
|
||||
data=get_notification_return_data(
|
||||
notification_id,
|
||||
notification,
|
||||
template_object)
|
||||
), 201
|
||||
else:
|
||||
return jsonify(
|
||||
data=_get_simulated_recipient_response_data(template_object)
|
||||
), 200
|
||||
return jsonify(
|
||||
data=get_notification_return_data(
|
||||
notification_id,
|
||||
notification,
|
||||
template_object)
|
||||
), 201
|
||||
|
||||
|
||||
def get_notification_return_data(notification_id, notification, template):
|
||||
@@ -314,18 +311,6 @@ def _simulated_recipient(to_address, notification_type):
|
||||
else to_address in current_app.config['SIMULATED_EMAIL_ADDRESSES'])
|
||||
|
||||
|
||||
def _get_simulated_recipient_response_data(template_object):
|
||||
response_data = {
|
||||
'body': template_object.replaced,
|
||||
'template_version': template_object._template['version']
|
||||
}
|
||||
|
||||
if template_object._template['template_type'] == 'email':
|
||||
response_data.update({'subject': template_object.replaced_subject})
|
||||
|
||||
return response_data
|
||||
|
||||
|
||||
def persist_notification(
|
||||
service,
|
||||
notification_id,
|
||||
|
||||
Reference in New Issue
Block a user