From 060e94326a0f35088fe9c21b1c5fc943e8d13ca7 Mon Sep 17 00:00:00 2001 From: Roland Thomas Date: Sun, 9 Jun 2024 21:55:42 -0400 Subject: [PATCH] Add remove_item_by_name to item_list_manager.py --- cli/item_list_manager.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cli/item_list_manager.py b/cli/item_list_manager.py index 7f7086c..b8ea043 100644 --- a/cli/item_list_manager.py +++ b/cli/item_list_manager.py @@ -45,12 +45,22 @@ class ItemManager: else: print(f"Item with ID {item_id} not found.") - def search_by_name(self, name: str) -> Optional[Item]: - return self.items_by_name.get(name) + def remove_item_by_name(self, name: str): + if name in self.items_by_name: + item_to_remove = self.items_by_name.pop(name) + self.ordered_items = [item for item in self.ordered_items if item.name != name] + if item_to_remove.id in self.items_by_id: + del self.items_by_id[item_to_remove.id] + print(f"Item removed: {item_to_remove}") + else: + print(f"Item with name {name} not found.") def search_by_id(self, item_id: str) -> Optional[Item]: return self.items_by_id.get(item_id) + def search_by_name(self, name: str) -> Optional[Item]: + return self.items_by_name.get(name) + def get_all_items(self) -> List[Item]: return self.ordered_items