Update model to remove the string length restriction.

Moved logic to the dao from the endpoint.
This commit is contained in:
Rebecca Law
2017-06-19 12:25:05 +01:00
parent effb99dca8
commit 6202da7dea
6 changed files with 63 additions and 49 deletions

View File

@@ -551,15 +551,7 @@ def create_service_inbound_api(service_id):
try:
save_service_inbound_api(inbound_api)
except SQLAlchemyError as e:
if hasattr(e, 'orig') and hasattr(e.orig, 'pgerror')and e.orig.pgerror\
and ('duplicate key value violates unique constraint "ix_service_inbound_api_service_id"'
in e.orig.pgerror):
return jsonify(
result='error',
message={'name': ["You can only have one URL and bearer token for your service."]}
), 400
else:
raise e
return handle_sql_errror(e)
return jsonify(data=inbound_api.serialize()), 201
@@ -571,14 +563,10 @@ def update_service_inbound_api(service_id, inbound_api_id):
to_update = get_service_inbound_api(inbound_api_id, service_id)
if data.get("url", None):
to_update.url = data["url"]
if data.get("bearer_token", None):
to_update.bearer_token = generate_secret(data["bearer_token"])
to_update.updated_by_id = data["updated_by_id"]
to_update.updated_at = datetime.utcnow()
reset_service_inbound_api(to_update)
reset_service_inbound_api(service_inbound_api=to_update,
updated_by_id=data["updated_by_id"],
url=data.get("url", None),
bearer_token=data.get("bearer_token", None))
return jsonify(data=to_update.serialize()), 200
@@ -587,3 +575,20 @@ 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
def handle_sql_errror(e):
if hasattr(e, 'orig') and hasattr(e.orig, 'pgerror') and e.orig.pgerror \
and ('duplicate key value violates unique constraint "ix_service_inbound_api_service_id"'
in e.orig.pgerror):
return jsonify(
result='error',
message={'name': ["You can only have one URL and bearer token for your service."]}
), 400
elif hasattr(e, 'orig') and hasattr(e.orig, 'pgerror') and e.orig.pgerror \
and ('insert or update on table "service_inbound_api" violates '
'foreign key constraint "service_inbound_api_service_id_fkey"'
in e.orig.pgerror):
return jsonify(result='error', message="No result found"), 404
else:
raise e