Editable and removable datasets #8
@@ -175,6 +175,26 @@ def get_dataset(dataset_id):
|
|||||||
except Exception:
|
except Exception:
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
return jsonify({"error": "An unexpected error occured"}), 500
|
return jsonify({"error": "An unexpected error occured"}), 500
|
||||||
|
|
||||||
|
@app.route("/dataset/<int:dataset_id>", methods=["DELETE"])
|
||||||
|
@jwt_required()
|
||||||
|
def delete_dataset(dataset_id):
|
||||||
|
try:
|
||||||
|
user_id = int(get_jwt_identity())
|
||||||
|
|
||||||
|
if not dataset_manager.authorize_user_dataset(dataset_id, user_id):
|
||||||
|
raise NotAuthorisedException("This user is not authorised to access this dataset")
|
||||||
|
|
||||||
|
dataset_manager.delete_dataset_info(dataset_id)
|
||||||
|
dataset_manager.delete_dataset_content(dataset_id)
|
||||||
|
return jsonify({"message": f"Dataset {dataset_id} metadata and content successfully deleted"}), 200
|
||||||
|
except NotAuthorisedException:
|
||||||
|
return jsonify({"error": "User is not authorised to access this content"}), 403
|
||||||
|
except NonExistentDatasetException:
|
||||||
|
return jsonify({"error": "Dataset does not exist"}), 404
|
||||||
|
except Exception:
|
||||||
|
print(traceback.format_exc())
|
||||||
|
return jsonify({"error": "An unexpected error occured"}), 500
|
||||||
|
|
||||||
@app.route("/dataset/<int:dataset_id>/status", methods=["GET"])
|
@app.route("/dataset/<int:dataset_id>/status", methods=["GET"])
|
||||||
@jwt_required()
|
@jwt_required()
|
||||||
|
|||||||
@@ -143,4 +143,20 @@ class DatasetManager:
|
|||||||
print(result)
|
print(result)
|
||||||
raise NonExistentDatasetException(f"Dataset {dataset_id} does not exist")
|
raise NonExistentDatasetException(f"Dataset {dataset_id} does not exist")
|
||||||
|
|
||||||
return result[0]
|
return result[0]
|
||||||
|
|
||||||
|
def delete_dataset_info(self, dataset_id: int):
|
||||||
|
query = """
|
||||||
|
DELETE FROM datasets
|
||||||
|
WHERE id = %s
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.db.execute(query, (dataset_id, ))
|
||||||
|
|
||||||
|
def delete_dataset_content(self, dataset_id: int):
|
||||||
|
query = """
|
||||||
|
DELETE FROM events
|
||||||
|
WHERE id = %s
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.db.execute(query, (dataset_id, ))
|
||||||
Reference in New Issue
Block a user