feat: add delete game functionality for admins

This commit is contained in:
Manuel Weiser 2024-09-02 11:42:55 +02:00
parent bdb693c361
commit c49db43a43

View File

@ -113,3 +113,14 @@ def edit_game(game_id):
db.session.commit()
return jsonify({'message': 'Game updated!'}), 200
@user_bp.route('/games/<int:game_id>', 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