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