@RequestMapping(value = "/waiter/bills/{billId}", method = RequestMethod.GET) public String showBillInWaiter( @PathVariable("billId") String billId, Model uiModel, Locale locale) { // warmup stuff Bill bill = warmupRestaurant(billId, uiModel); Restaurant resto = bill.getDiningTable().getRestaurant(); List<Order> allPreparedOrders = orderService.findPreparedOrdersForRestaurant(resto); uiModel.addAttribute("allPreparedOrders", allPreparedOrders); List<Bill> allSubmittedBills = billService.findSubmittedBillsForRestaurant(resto); uiModel.addAttribute("allSubmittedBills", allSubmittedBills); uiModel.addAttribute( "message", new Message( "info", messageSource.getMessage("label_bill_amount", new Object[] {}, locale) + ": " + bill.getPriceAllOrders() + " " + messageSource.getMessage("label_currency", new Object[] {}, locale))); return "hartigehap/waiter"; }
private Bill warmupRestaurant(String billId, Model uiModel) { Bill bill = billService.findById(Long.valueOf(billId)); Collection<Restaurant> restaurants = restaurantService.findAll(); uiModel.addAttribute("restaurants", restaurants); Restaurant restaurant = restaurantService.fetchWarmedUp(bill.getDiningTable().getRestaurant().getId()); uiModel.addAttribute("restaurant", restaurant); return bill; }
@RequestMapping(value = "/waiter/bills/{billId}", method = RequestMethod.PUT) public String receiveBillEvent( @PathVariable("billId") String billId, @RequestParam String event, Model uiModel) { Bill bill = warmupRestaurant(billId, uiModel); switch (event) { case "billHasBeenPaid": billHasBeenPaid(bill); break; default: log.error("Internal error: event " + event + " not recognized"); break; } return "redirect:/restaurants/" + bill.getDiningTable().getRestaurant().getId() + "/waiter"; }
private void billHasBeenPaid(Bill bill) { try { billService.billHasBeenPaid(bill); } catch (StateException e) { log.error( "Internal error has occurred! Order " + Long.valueOf(bill.getId()) + "has not been changed to served state!", e); } }