Exemplo n.º 1
0
 def give_options(self):
     """
     Prompt the user with the choices.
     """
     options = [
         self.catalogue.display_available_items, self.catalogue.search,
         self.check_out, self.return_item, self.catalogue.add_item,
         self.catalogue.remove_item
     ]
     try:
         answer = input("-------------------------------\n"
                        "(1) Display available items \n"
                        "(2) Find an item by title\n"
                        "(3) Check out an item\n"
                        "(4) Return an item\n"
                        "(5) Add an item\n"
                        "(6) Remove an item\n"
                        "Please select: \n")
         InputHandler.validate(len(options), answer)
         answer = int(answer) - 1
     except ValueError:
         print("\n[Error] Please type an integer!")
     except CommandNotFoundException as e:
         print(f"{e}")
     else:
         if answer == 1:
             title = input("Enter the item title: ")
             options[answer](title)
         elif answer in [2, 3, 5]:
             call_number = input("Enter the call number of the item: ")
             options[answer](call_number)
         else:
             options[answer]()
Exemplo n.º 2
0
 def add_item(self):
     """
     Adds a new item to the catalogue if not exists yet.
     """
     passed = False
     while not passed:
         try:
             print("Which item type would you like to add?")
             print("1. Book\n2. DVD\n3. Journal")
             answer = input("Enter your choice (1-3)")
             InputHandler.validate(len(self.item_factory_map), answer)
             item_factory = self.item_factory_map.get(int(answer))
             item = item_factory().create_item()
         except ValueError:
             print("\n[Error] Please type an integer!")
         except CommandNotFoundException as e:
             print(f"{e}")
         else:
             passed = True
             if not self.item_exists(item.call_number):
                 self.item_list[item.call_number] = item
                 print(f"Item({item.call_number}) bas been added.")
             else:
                 print("This call number already exists.")