diff --git a/app/controller/household/household_controller.py b/app/controller/household/household_controller.py index 0cb7e91..810a47c 100644 --- a/app/controller/household/household_controller.py +++ b/app/controller/household/household_controller.py @@ -7,6 +7,7 @@ from app.service.import_language import importLanguage from app.service.file_has_access_or_download import file_has_access_or_download from .schemas import AddHousehold, UpdateHousehold, UpdateHouseholdMember +from flask_socketio import close_room household = Blueprint('household', __name__) @@ -99,7 +100,8 @@ def updateHousehold(args, household_id): @jwt_required() @authorize_household(required=RequiredRights.ADMIN) def deleteHouseholdById(household_id): - Household.delete_by_id(household_id) + if Household.delete_by_id(household_id): + close_room(household_id) return jsonify({'msg': 'DONE'}) diff --git a/app/controller/shoppinglist/shoppinglist_controller.py b/app/controller/shoppinglist/shoppinglist_controller.py index 2ebd2bf..213eba2 100644 --- a/app/controller/shoppinglist/shoppinglist_controller.py +++ b/app/controller/shoppinglist/shoppinglist_controller.py @@ -72,6 +72,10 @@ def updateItemDescription(args, id, item_id): con.description = args['description'] or '' con.save() + socketio.emit("shoppinglist_item:add", { + "item": con.obj_to_item_dict(), + "shoppinglist": shoppinglist.obj_to_dict() + }, to=shoppinglist.household_id) return jsonify(con.obj_to_item_dict()) @@ -213,10 +217,11 @@ def removeShoppinglistItem(args, id): con = removeShoppinglistItem( shoppinglist, args['item_id'], args['removed_at'] if 'removed_at' in args else None) - if con: socketio.emit("shoppinglist_item:remove", { - "item": con.obj_to_item_dict(), - "shoppinglist": shoppinglist.obj_to_dict() - }, to=shoppinglist.household_id) + if con: + socketio.emit("shoppinglist_item:remove", { + "item": con.obj_to_item_dict(), + "shoppinglist": shoppinglist.obj_to_dict() + }, to=shoppinglist.household_id) return jsonify({'msg': "DONE"}) @@ -233,10 +238,11 @@ def removeShoppinglistItems(args, id): for arg in args['items']: con = removeShoppinglistItem( shoppinglist, arg['item_id'], arg['removed_at'] if 'removed_at' in arg else None) - if con: socketio.emit("shoppinglist_item:remove", { - "item": con.obj_to_item_dict(), - "shoppinglist": shoppinglist.obj_to_dict() - }, to=shoppinglist.household_id) + if con: + socketio.emit("shoppinglist_item:remove", { + "item": con.obj_to_item_dict(), + "shoppinglist": shoppinglist.obj_to_dict() + }, to=shoppinglist.household_id) return jsonify({'msg': "DONE"}) @@ -289,7 +295,12 @@ def addRecipeItems(args, id): db.session.add(con) db.session.add( - History.create_added_without_save(shoppinglist, item)) + History.create_added_without_save(shoppinglist, item, description)) + + socketio.emit("shoppinglist_item:add", { + "item": con.obj_to_item_dict(), + "shoppinglist": shoppinglist.obj_to_dict() + }, to=shoppinglist.household_id) db.session.commit() except Exception as e: diff --git a/app/helpers/db_model_mixin.py b/app/helpers/db_model_mixin.py index b7d4899..de48a6a 100644 --- a/app/helpers/db_model_mixin.py +++ b/app/helpers/db_model_mixin.py @@ -54,10 +54,12 @@ def find_by_id(cls, target_id: int) -> Self: return cls.query.filter(cls.id == target_id).first() @classmethod - def delete_by_id(cls, target_id: int): + def delete_by_id(cls, target_id: int) -> bool: mc = cls.find_by_id(target_id) if mc: mc.delete() + return True + return False @classmethod def all(cls) -> list[Self]: