Add remove_item_by_name to item_list_manager.py
This commit is contained in:
parent
679ce2eddf
commit
060e94326a
|
@ -45,12 +45,22 @@ class ItemManager:
|
||||||
else:
|
else:
|
||||||
print(f"Item with ID {item_id} not found.")
|
print(f"Item with ID {item_id} not found.")
|
||||||
|
|
||||||
def search_by_name(self, name: str) -> Optional[Item]:
|
def remove_item_by_name(self, name: str):
|
||||||
return self.items_by_name.get(name)
|
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]:
|
def search_by_id(self, item_id: str) -> Optional[Item]:
|
||||||
return self.items_by_id.get(item_id)
|
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]:
|
def get_all_items(self) -> List[Item]:
|
||||||
return self.ordered_items
|
return self.ordered_items
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue