commit
a90eca923d
@ -91,15 +91,15 @@ def DeleteShip():
|
||||
|
||||
# read the user data from the JWT token (set when login is performed)
|
||||
user_data = check_jwt()
|
||||
ship_id = request.args.get("id")
|
||||
|
||||
if 'id' in request.args:
|
||||
options = {}
|
||||
options["id"] = request.args.get("id")
|
||||
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
|
||||
ship_id = request.args.get("id")
|
||||
InputValidationShip.evaluate_delete_data(user_data, ship_id)
|
||||
return impl.ships.DeleteShip(options)
|
||||
|
||||
|
||||
@ -60,7 +60,11 @@ class InputValidationShip():
|
||||
return
|
||||
|
||||
@staticmethod
|
||||
def evaluate_delete_data(user_data:dict, ship_id:int):
|
||||
def evaluate_delete_data(user_data:dict, ship_id:typing.Optional[int]):
|
||||
if ship_id is None:
|
||||
raise ValidationError({"id":f"The ship id must be provided."})
|
||||
ship_id = int(ship_id)
|
||||
|
||||
# 1.) Only users of type BSMD are allowed to PUT
|
||||
InputValidationShip.check_user_is_bsmd_type(user_data)
|
||||
|
||||
@ -123,18 +127,15 @@ class InputValidationShip():
|
||||
return
|
||||
|
||||
@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
|
||||
makes sure, that the request contains and ID, has a matching entry in the database, and the
|
||||
database entry may not have a deletion state already.
|
||||
"""
|
||||
if ship_id is None:
|
||||
raise ValidationError({"id":f"The ship id must be provided."})
|
||||
|
||||
response, status_code, header = GetShips(token=None)
|
||||
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:
|
||||
raise ValidationError({"id":f"Could not find a ship with the specified ID. Selected: {ship_id}"})
|
||||
|
||||
|
||||
@ -108,8 +108,10 @@ class InputValidationTimes():
|
||||
return
|
||||
|
||||
@staticmethod
|
||||
def evaluate_delete_data(user_data:dict, times_id:int):
|
||||
# #TODO_determine: is times_id always an int or does the request.args call provide a string?
|
||||
def evaluate_delete_data(user_data:dict, times_id:typing.Optional[int]):
|
||||
# 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
|
||||
|
||||
# 1.) The dataset entry may not be deleted already
|
||||
|
||||
Reference in New Issue
Block a user