use of com.salesmanager.shop.store.model.paging.PaginationData in project shopizer by shopizer-ecommerce.
the class CustomerOrdersController method listOrders.
@PreAuthorize("hasRole('AUTH_CUSTOMER')")
@RequestMapping(value = "/orders.html", method = { RequestMethod.GET, RequestMethod.POST })
public String listOrders(Model model, @RequestParam(value = "page", defaultValue = "1") final int page, HttpServletRequest request, HttpServletResponse response) throws Exception {
LOGGER.info("Fetching orders for current customer");
MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
Language language = getSessionAttribute(Constants.LANGUAGE, request);
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Customer customer = null;
if (auth != null && request.isUserInRole("AUTH_CUSTOMER")) {
customer = customerFacade.getCustomerByUserName(auth.getName(), store);
}
if (customer == null) {
return "redirect:/" + Constants.SHOP_URI;
}
PaginationData paginaionData = createPaginaionData(page, Constants.MAX_ORDERS_PAGE);
ReadableOrderList readable = orderFacade.getReadableOrderList(store, customer, (paginaionData.getOffset() - 1), paginaionData.getPageSize(), language);
model.addAttribute("customerOrders", readable);
if (readable != null) {
model.addAttribute("paginationData", calculatePaginaionData(paginaionData, Constants.MAX_ORDERS_PAGE, readable.getNumber()));
} else {
model.addAttribute("paginationData", null);
}
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Customer.customerOrders).append(".").append(store.getStoreTemplate());
return template.toString();
}
Aggregations