From 64e3f9eea84ebd3aaf9b2c224ba6d89888764d4a Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Wed, 4 Mar 2026 21:38:06 +0000 Subject: [PATCH] feat: implement PATCH dataset route At the moment only allows for the updating of the name. Which seems to be the only editable part of dataset metadata. --- server/app.py | 25 +++++++++++++++++++++++++ server/core/datasets.py | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/server/app.py b/server/app.py index f490fe9..53141cc 100644 --- a/server/app.py +++ b/server/app.py @@ -176,6 +176,31 @@ def get_dataset(dataset_id): print(traceback.format_exc()) return jsonify({"error": "An unexpected error occured"}), 500 +@app.route("/dataset/", methods=["PATCH"]) +@jwt_required() +def update_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") + + body = request.get_json() + new_name = body.get("name") + + if not new_name or not new_name.strip(): + return jsonify({"error": "A valid name must be provided"}), 400 + + dataset_manager.update_dataset_name(dataset_id, new_name.strip()) + return jsonify({"message": f"Dataset {dataset_id} renamed to '{new_name.strip()}'"}), 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 occurred"}), 500 + @app.route("/dataset/", methods=["DELETE"]) @jwt_required() def delete_dataset(dataset_id): diff --git a/server/core/datasets.py b/server/core/datasets.py index 9b15f74..5886cfc 100644 --- a/server/core/datasets.py +++ b/server/core/datasets.py @@ -145,6 +145,10 @@ class DatasetManager: return result[0] + def update_dataset_name(self, dataset_id: int, new_name: str): + query = "UPDATE datasets SET name = %s WHERE id = %s" + self.db.execute(query, (new_name, dataset_id)) + def delete_dataset_info(self, dataset_id: int): query = "DELETE FROM datasets WHERE id = %s"