app_customer.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. if len(bookList) == 0:
  38. display.error('No book order for', login, 'yet.')
  39. else:
  40. bookId = bookAsker.select(bookList)
  41. itemList = consumer.getItemsOfOrder(bookId)
  42. if len(itemList) == 0:
  43. display.error('No item found for order', bookId)
  44. else:
  45. display.orderedItemList(itemList)
  46. elif action == 'list warehouses':
  47. houseList = consumer.getWarehousesOfCompany(login)
  48. if len(houseList) == 0:
  49. display.error('No warehouse for', login, 'yet.')
  50. else:
  51. display.warehouseList(houseList)
  52. else:
  53. display.notImplemented(action)
  54. display.end()