Search in sources :

Example 6 with ReadableOrderList

use of com.salesmanager.shop.model.order.v0.ReadableOrderList in project shopizer by shopizer-ecommerce.

the class OrderRESTController method listOrders.

/**
 * Get a list of orders
 * accept request parameter 'lang' [en,fr...] otherwise store dafault language
 * accept request parameter 'start' start index for count
 * accept request parameter 'max' maximum number count, otherwise returns all
 * @param store
 * @param order
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/{store}/orders/", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.ACCEPTED)
@ResponseBody
public ReadableOrderList listOrders(@PathVariable final String store, HttpServletRequest request, HttpServletResponse response) throws Exception {
    MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
    if (merchantStore != null) {
        if (!merchantStore.getCode().equals(store)) {
            merchantStore = null;
        }
    }
    if (merchantStore == null) {
        merchantStore = merchantStoreService.getByCode(store);
    }
    if (merchantStore == null) {
        LOGGER.error("Merchant store is null for code " + store);
        response.sendError(503, "Merchant store is null for code " + store);
        return null;
    }
    // get additional request parameters for orders
    String lang = request.getParameter(Constants.LANG);
    String start = request.getParameter(Constants.START);
    String max = request.getParameter(Constants.MAX);
    int startCount = 0;
    int maxCount = 0;
    if (StringUtils.isBlank(lang)) {
        lang = merchantStore.getDefaultLanguage().getCode();
    }
    Language language = languageService.getByCode(lang);
    if (language == null) {
        LOGGER.error("Language is null for code " + lang);
        response.sendError(503, "Language is null for code " + lang);
        return null;
    }
    try {
        startCount = Integer.parseInt(start);
    } catch (Exception e) {
        LOGGER.info("Invalid value for start " + start);
    }
    try {
        maxCount = Integer.parseInt(max);
    } catch (Exception e) {
        LOGGER.info("Invalid value for max " + max);
    }
    ReadableOrderList returnList = orderFacade.getReadableOrderList(merchantStore, startCount, maxCount, language);
    return returnList;
}
Also used : ReadableOrderList(com.salesmanager.shop.model.order.v0.ReadableOrderList) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore)

Example 7 with ReadableOrderList

use of com.salesmanager.shop.model.order.v0.ReadableOrderList 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

ReadableOrderList (com.salesmanager.shop.model.order.v0.ReadableOrderList)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Customer (com.salesmanager.core.model.customer.Customer)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)4 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)3 Language (com.salesmanager.core.model.reference.language.Language)3 PersistableCustomer (com.salesmanager.shop.model.customer.PersistableCustomer)3 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)3 ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)2 ReadableOrder (com.salesmanager.shop.model.order.v0.ReadableOrder)2 ReadableCustomerPopulator (com.salesmanager.shop.populator.customer.ReadableCustomerPopulator)2 OrderCriteria (com.salesmanager.core.model.order.OrderCriteria)1 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)1 PaginationData (com.salesmanager.shop.store.model.paging.PaginationData)1 Principal (java.security.Principal)1 LocalDate (java.time.LocalDate)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1