/** * Request method to show all purchases * * @param page number of purchases page * @param unverified request unverified * @param uncompleted request uncompleted * @return view */ @RequestMapping(value = "/purchases", method = RequestMethod.GET) public ModelAndView purchasesGet( @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "false") boolean unverified, @RequestParam(defaultValue = "false") boolean uncompleted) { ModelAndView view = new AdminModelAndView("purchases"); if (unverified) { view.addObject("purchases", purchaseService.getUnverified()); return view; } if (uncompleted) { view.addObject("purchases", purchaseService.getUncompleted()); return view; } int pageCount = purchaseService.getPurchasesCount(); if (page < 1 || page > pageCount) { page = 1; } List<Purchase> listPurchases = purchaseService.getPurchasesInRange(page); view.addObject("purchases", listPurchases); view.addObject("pageCount", pageCount); view.addObject("page", page); return view; }
/** * Admin root path * * @return view */ @RequestMapping(method = RequestMethod.GET) public ModelAndView adminHome() { ModelAndView view = new AdminModelAndView("admin"); view.addObject("usersCount", userService.getAllUsers().size()); view.addObject("productsCount", productService.getAllProducts().size()); view.addObject("categoriesCount", categoryService.getAllCategories().size()); view.addObject("purchasesCount", purchaseService.getAllPurchases().size()); view.addObject("promotions", productService.getOnPromotion()); return view; }
/** * Request method to get purchase for editing * * @param purchase to edit * @return view */ @RequestMapping(value = "/purchases/edit", method = RequestMethod.POST) public String purchaseEditPOST( @ModelAttribute Purchase purchase, @RequestParam(defaultValue = "false") boolean shipped) { if (shipped) { purchase.setDateShipped(new Date()); } else { purchase.setDateShipped(null); } purchaseService.updatePurchase(purchase); return "redirect:/admin/purchases"; }
/** @return number of uncompleted purchases */ @ModelAttribute("uncompletedCount") public long uncompletedCount() { return purchaseService.uncompletedCount(); }
/** @return number of unverified purchases */ @ModelAttribute("unverifiedCount") public long unverifiedCount() { return purchaseService.unverifiedCount(); }
/** * Request method to get purchase for editing * * @param id of purchase * @return view */ @RequestMapping(value = "/purchases/edit", method = RequestMethod.GET) public ModelAndView getPurchase(@RequestParam int id) { return new ModelAndView( "/admin-pages/purchase_form", "purchase", purchaseService.getPurchase(id)); }