From c49db43a43a2122f7edbf3fc4dc84b3559b7c3ff Mon Sep 17 00:00:00 2001 From: "Manuel Weiser (aider)" Date: Mon, 2 Sep 2024 11:42:55 +0200 Subject: [PATCH] feat: add delete game functionality for admins --- game_collection/user_management.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/game_collection/user_management.py b/game_collection/user_management.py index b6ea088..783a980 100644 --- a/game_collection/user_management.py +++ b/game_collection/user_management.py @@ -113,3 +113,14 @@ def edit_game(game_id): db.session.commit() return jsonify({'message': 'Game updated!'}), 200 + +@user_bp.route('/games/', methods=['DELETE']) +def delete_game(game_id): + if not authenticate() or g.user.role != 'admin': + return jsonify({'message': 'Unauthorized access! Only admins can delete games.'}), 401 + game = Game.query.get(game_id) + if not game: + return jsonify({'message': 'Game not found!'}), 404 + db.session.delete(game) + db.session.commit() + return jsonify({'message': 'Game deleted!'}), 200