Make set_as_broadcast_service use a single DB commit

We don't want things in a half state if there is an error during the
method. Therefore, we move it all into a single function that is wrapped
in a transaction.

Note, we copy the approach of
https://github.com/alphagov/notifications-api/blob/master/app/dao/services_dao.py#L293
by having a single new dao function that does all the DB work.
This commit is contained in:
David McDonald
2021-02-15 14:54:36 +00:00
parent f9c87bafa3
commit 6fcda6debb
5 changed files with 73 additions and 57 deletions

View File

@@ -16,7 +16,7 @@ from app.dao.jobs_dao import dao_create_job
from app.dao.notifications_dao import dao_create_notification
from app.dao.organisation_dao import dao_create_organisation, dao_add_service_to_organisation
from app.dao.services_dao import (dao_create_service, dao_add_user_to_service)
from app.dao.service_broadcast_settings_dao import insert_or_update_service_broadcast_settings
from app.dao.broadcast_service_dao import insert_or_update_service_broadcast_settings
from app.dao.templates_dao import dao_create_template
from app.dao.users_dao import create_secret_code, create_user_code
from app.history_meta import create_history