diff --git a/game_collection/app.py b/game_collection/app.py index d5cef03..96e10fa 100644 --- a/game_collection/app.py +++ b/game_collection/app.py @@ -73,6 +73,23 @@ def get_games(): }) return jsonify(games_list) +@app.route('/games/', methods=['DELETE']) +def delete_game(game_id): + if not authenticate(): + return jsonify({'message': 'Unauthorized access!'}), 401 + game = Game.query.get(game_id) + if not game: + return jsonify({'message': 'Game not found!'}), 404 + + # Delete the image file + image_path = os.path.join(app.instance_path, game.image) + if os.path.exists(image_path): + os.remove(image_path) + + db.session.delete(game) + db.session.commit() + return jsonify({'message': 'Game deleted!'}), 200 + @app.route('/games/search', methods=['GET']) def search_game_api(): if not authenticate(): # Ensure the user is authenticated