app_product.py 943 B

123456789101112131415161718192021222324252627282930313233343536
  1. from consumer.connect import DataConsumer
  2. from consumer.credentials import getCredentials
  3. from model.product import Product
  4. from basic_display import BasicDisplay
  5. from cli.pro_action_asker import ProActionAsker
  6. from cli.name_asker import NameAsker
  7. display = BasicDisplay()
  8. display.title('Product management application')
  9. credentials = getCredentials()
  10. consumer = DataConsumer(credentials)
  11. actionAsker = ProActionAsker()
  12. nameAsker = NameAsker()
  13. running = True
  14. while running:
  15. ans = actionAsker.ask()
  16. action = ans['action']
  17. if action == 'quit':
  18. running = False
  19. elif action == 'list':
  20. proList = consumer.getProductSet()
  21. display.productList(proList)
  22. elif action == 'add':
  23. name = nameAsker.ask()
  24. print('Adding product', name, '...')
  25. consumer.addProduct(name)
  26. consumer.commit()
  27. print('Done.')
  28. else:
  29. display.notImplemented(action)
  30. display.end()