app_customer.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from consumer.connect import DataConsumer
  2. from consumer.credentials import getCredentials
  3. from basic_display import BasicDisplay
  4. from cli.select import Selecter
  5. from cli.pass_asker import PassAsker
  6. from cli.customer_action_asker import CustomerActionAsker
  7. from cli.book_asker import BookAsker
  8. display = BasicDisplay()
  9. display.title('Customer application')
  10. credentials = getCredentials()
  11. consumer = DataConsumer(credentials)
  12. companyAsker = Selecter('Choose your company')
  13. passAsker = PassAsker()
  14. actionAsker = CustomerActionAsker()
  15. bookAsker = BookAsker()
  16. # Login phase
  17. compList = consumer.getCompanyNames()
  18. compList.append('dev')
  19. login = companyAsker.selectInto(compList)
  20. pwd = passAsker.ask()
  21. # Dummy password check
  22. if pwd != "":
  23. print('Successfully logged as', login)
  24. else:
  25. print('Name', login, 'not recognized.')
  26. print('(dummy password check : enter an non-empty password)')
  27. exit()
  28. # Action phase
  29. running = True
  30. while running:
  31. ans = actionAsker.ask()
  32. action = ans['action']
  33. if action == 'quit':
  34. running = False
  35. elif action == 'list orders':
  36. bookList = consumer.getOrdersOfCompany(login)
  37. bookId = bookAsker.select(bookList)
  38. itemList = consumer.getItemsOfOrder(bookId)
  39. display.orderedItemList(itemList)
  40. else:
  41. print('Action', action, 'not implemented yet.')
  42. print('End')