Merge pull request #1933 from alphagov/delete-service-stuff

Delete service apis (callback + inbound)
This commit is contained in:
Leo Hemsted
2018-07-06 15:19:01 +01:00
committed by GitHub
6 changed files with 160 additions and 76 deletions

View File

@@ -616,8 +616,11 @@ def migrate_data_to_ft_notification_status(start_date, end_date):
"""
result = db.session.execute(sql, {"start": process_date, "end": process_date + timedelta(days=1)})
db.session.commit()
print('ft_notification_status: --- Completed took {}ms. Migrated {} rows.'.format(datetime.now() - start_time,
result.rowcount))
print('ft_notification_status: --- Completed took {}ms. Migrated {} rows for {}.'.format(
datetime.now() - start_time,
result.rowcount,
process_date
))
process_date += timedelta(days=1)
total_updated += result.rowcount

View File

@@ -32,3 +32,8 @@ def get_service_callback_api(service_callback_api_id, service_id):
def get_service_callback_api_for_service(service_id):
return ServiceCallbackApi.query.filter_by(service_id=service_id).first()
@transactional
def delete_service_callback_api(service_callback_api):
db.session.delete(service_callback_api)

View File

@@ -33,3 +33,8 @@ def get_service_inbound_api(service_inbound_api_id, service_id):
def get_service_inbound_api_for_service(service_id):
return ServiceInboundApi.query.filter_by(service_id=service_id).first()
@transactional
def delete_service_inbound_api(service_inbound_api):
db.session.delete(service_inbound_api)

View File

@@ -6,7 +6,8 @@ from flask import (
from sqlalchemy.exc import SQLAlchemyError
from app.errors import (
register_errors
register_errors,
InvalidRequest
)
from app.models import (
ServiceInboundApi,
@@ -20,12 +21,14 @@ from app.service.service_callback_api_schema import (
from app.dao.service_inbound_api_dao import (
save_service_inbound_api,
get_service_inbound_api,
reset_service_inbound_api
reset_service_inbound_api,
delete_service_inbound_api,
)
from app.dao.service_callback_api_dao import (
save_service_callback_api,
get_service_callback_api,
reset_service_callback_api
reset_service_callback_api,
delete_service_callback_api,
)
service_callback_blueprint = Blueprint('service_callback', __name__, url_prefix='/service/<uuid:service_id>')
@@ -61,13 +64,25 @@ def update_service_inbound_api(service_id, inbound_api_id):
return jsonify(data=to_update.serialize()), 200
@service_callback_blueprint.route('/inbound-api/<uuid:inbound_api_id>', methods=["GET"])
@service_callback_blueprint.route('/inbound-api/<uuid:inbound_api_id>', methods=['GET'])
def fetch_service_inbound_api(service_id, inbound_api_id):
inbound_api = get_service_inbound_api(inbound_api_id, service_id)
return jsonify(data=inbound_api.serialize()), 200
@service_callback_blueprint.route('/inbound-api/<uuid:inbound_api_id>', methods=['DELETE'])
def remove_service_inbound_api(service_id, inbound_api_id):
inbound_api = get_service_inbound_api(inbound_api_id, service_id)
if not inbound_api:
error = 'Service inbound API not found'
raise InvalidRequest(error, status_code=404)
delete_service_inbound_api(inbound_api)
return '', 204
@service_callback_blueprint.route('/delivery-receipt-api', methods=['POST'])
def create_service_callback_api(service_id):
data = request.get_json()
@@ -103,6 +118,18 @@ def fetch_service_callback_api(service_id, callback_api_id):
return jsonify(data=callback_api.serialize()), 200
@service_callback_blueprint.route('/delivery-receipt-api/<uuid:callback_api_id>', methods=['DELETE'])
def remove_service_callback_api(service_id, callback_api_id):
callback_api = get_service_callback_api(callback_api_id, service_id)
if not callback_api:
error = 'Service delivery receipt callback API not found'
raise InvalidRequest(error, status_code=404)
delete_service_callback_api(callback_api)
return '', 204
def handle_sql_error(e, table_name):
if hasattr(e, 'orig') and hasattr(e.orig, 'pgerror') and e.orig.pgerror \
and ('duplicate key value violates unique constraint "ix_{}_service_id"'.format(table_name)