feat: add delete_game route to remove game and its associated image file
This commit is contained in:
parent
56f8939b9d
commit
155ce5c9d5
@ -73,6 +73,23 @@ def get_games():
|
|||||||
})
|
})
|
||||||
return jsonify(games_list)
|
return jsonify(games_list)
|
||||||
|
|
||||||
|
@app.route('/games/<int:game_id>', 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'])
|
@app.route('/games/search', methods=['GET'])
|
||||||
def search_game_api():
|
def search_game_api():
|
||||||
if not authenticate(): # Ensure the user is authenticated
|
if not authenticate(): # Ensure the user is authenticated
|
||||||
|
Loading…
Reference in New Issue
Block a user