Search in sources :

Example 1 with PaginationData

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();
}
Also used : ReadableOrderList(com.salesmanager.shop.model.order.v0.ReadableOrderList) PaginationData(com.salesmanager.shop.store.model.paging.PaginationData) Language(com.salesmanager.core.model.reference.language.Language) Customer(com.salesmanager.core.model.customer.Customer) Authentication(org.springframework.security.core.Authentication) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Customer (com.salesmanager.core.model.customer.Customer)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Language (com.salesmanager.core.model.reference.language.Language)1 ReadableOrderList (com.salesmanager.shop.model.order.v0.ReadableOrderList)1 PaginationData (com.salesmanager.shop.store.model.paging.PaginationData)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 Authentication (org.springframework.security.core.Authentication)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1