correcting an issue in the DELETE methods for SHIPS and TIMES, where the ID may have been provided as a null value or was incorrectly converted (string instead of integer)
This commit is contained in:
parent
82969c8726
commit
82ad56812e
@ -91,16 +91,19 @@ def DeleteShip():
|
|||||||
|
|
||||||
# read the user data from the JWT token (set when login is performed)
|
# read the user data from the JWT token (set when login is performed)
|
||||||
user_data = check_jwt()
|
user_data = check_jwt()
|
||||||
ship_id = request.args.get("id")
|
|
||||||
|
|
||||||
if 'id' in request.args:
|
if 'id' in request.args:
|
||||||
options = {}
|
options = {}
|
||||||
options["id"] = request.args.get("id")
|
options["id"] = request.args.get("id")
|
||||||
else:
|
else:
|
||||||
return create_dynamic_exception_response(ex=ex, status_code=400, message="no id provided")
|
return create_dynamic_exception_response(ex=None, status_code=400, message="no id provided")
|
||||||
|
|
||||||
# validate the request data & user permissions
|
# validate the request data & user permissions
|
||||||
InputValidationShip.evaluate_delete_data(user_data, ship_id)
|
ship_id = request.args.get("id")
|
||||||
|
if ship_id is None:
|
||||||
|
return create_dynamic_exception_response(ex=None, status_code=400, message="no id provided")
|
||||||
|
|
||||||
|
InputValidationShip.evaluate_delete_data(user_data, int(ship_id))
|
||||||
return impl.ships.DeleteShip(options)
|
return impl.ships.DeleteShip(options)
|
||||||
|
|
||||||
except ValidationError as ex:
|
except ValidationError as ex:
|
||||||
|
|||||||
@ -123,7 +123,7 @@ class InputValidationShip():
|
|||||||
return
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def check_if_entry_is_already_deleted(ship_id:int):
|
def check_if_entry_is_already_deleted(ship_id:typing.Optional[int]):
|
||||||
"""
|
"""
|
||||||
When calling a delete request for ships, the dataset may not be deleted already. This method
|
When calling a delete request for ships, the dataset may not be deleted already. This method
|
||||||
makes sure, that the request contains and ID, has a matching entry in the database, and the
|
makes sure, that the request contains and ID, has a matching entry in the database, and the
|
||||||
@ -134,7 +134,7 @@ class InputValidationShip():
|
|||||||
|
|
||||||
response, status_code, header = GetShips(token=None)
|
response, status_code, header = GetShips(token=None)
|
||||||
ships = json.loads(response)
|
ships = json.loads(response)
|
||||||
existing_database_entries = [ship for ship in ships if ship.get("id")==ship_id]
|
existing_database_entries = [ship for ship in ships if ship.get("id")==int(ship_id)]
|
||||||
if len(existing_database_entries)==0:
|
if len(existing_database_entries)==0:
|
||||||
raise ValidationError({"id":f"Could not find a ship with the specified ID. Selected: {ship_id}"})
|
raise ValidationError({"id":f"Could not find a ship with the specified ID. Selected: {ship_id}"})
|
||||||
|
|
||||||
|
|||||||
@ -108,8 +108,10 @@ class InputValidationTimes():
|
|||||||
return
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def evaluate_delete_data(user_data:dict, times_id:int):
|
def evaluate_delete_data(user_data:dict, times_id:typing.Optional[int]):
|
||||||
# #TODO_determine: is times_id always an int or does the request.args call provide a string?
|
# 0.) an ID reference must be provided and will be converted to int
|
||||||
|
if times_id is None:
|
||||||
|
raise ValidationError({"id":"no times id provided"})
|
||||||
times_id = int(times_id) if not isinstance(times_id, int) else times_id
|
times_id = int(times_id) if not isinstance(times_id, int) else times_id
|
||||||
|
|
||||||
# 1.) The dataset entry may not be deleted already
|
# 1.) The dataset entry may not be deleted already
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user