Search in sources :

Example 1 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 for a given customer
 * 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/customer/{id}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.ACCEPTED)
@ResponseBody
public ReadableOrderList listOrders(@PathVariable final String store, @PathVariable final Long id, 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);
    }
    Customer customer = customerService.getById(id);
    if (customer == null) {
        LOGGER.error("Customer is null for id " + id);
        response.sendError(503, "Customer is null for id " + id);
        return null;
    }
    if (customer.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
        LOGGER.error("Customer is null for id " + id + " and store id " + store);
        response.sendError(503, "Customer is null for id " + id + " and store id " + store);
        return null;
    }
    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) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore)

Example 2 with ReadableOrderList

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

the class OrderPaymentApi method listCapturableOrders.

/**
 * An order can be pre-authorized but un captured. This metho returns all
 * order subject to be capturable For a given time frame
 *
 * @param startDate
 * @param endDate
 * @param request
 * @param response
 * @return ReadableOrderList
 * @throws Exception
 */
@RequestMapping(value = { "/private/orders/payment/capturable" }, method = RequestMethod.GET)
@ResponseStatus(HttpStatus.ACCEPTED)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ReadableOrderList listCapturableOrders(@RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate, @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
    try {
        // if startdate or enddate are null use default range (last 24
        // hours) DD-1 to DD
        Calendar cal = Calendar.getInstance();
        Date sDate = null;
        if (startDate != null) {
            sDate = Date.from(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
        } else {
            cal.add(Calendar.DATE, -1);
            sDate = cal.getTime();
        }
        Date eDate = null;
        if (endDate != null) {
            eDate = Date.from(endDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
        } else {
            eDate = new Date();
        }
        ReadableOrderList returnList = orderFacade.getCapturableOrderList(merchantStore, sDate, eDate, language);
        return returnList;
    } catch (Exception e) {
        LOGGER.error("Error while getting capturable payments", e);
        try {
            response.sendError(503, "Error while getting capturable payments " + e.getMessage());
        } catch (Exception ignore) {
        }
        return null;
    }
}
Also used : ReadableOrderList(com.salesmanager.shop.model.order.v0.ReadableOrderList) Calendar(java.util.Calendar) Date(java.util.Date) LocalDate(java.time.LocalDate) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with ReadableOrderList

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

the class OrderApi method list.

/**
 * List orders for authenticated customers
 *
 * @param start
 * @param count
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value = { "/auth/orders" }, method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public ReadableOrderList list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "count", required = false) Integer count, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) throws Exception {
    Principal principal = request.getUserPrincipal();
    String userName = principal.getName();
    Customer customer = customerService.getByNick(userName);
    if (customer == null) {
        response.sendError(401, "Error while listing orders, customer not authorized");
        return null;
    }
    if (page == null) {
        page = new Integer(0);
    }
    if (count == null) {
        count = new Integer(100);
    }
    ReadableCustomer readableCustomer = new ReadableCustomer();
    ReadableCustomerPopulator customerPopulator = new ReadableCustomerPopulator();
    customerPopulator.populate(customer, readableCustomer, merchantStore, language);
    ReadableOrderList returnList = orderFacade.getReadableOrderList(merchantStore, customer, page, count, language);
    if (returnList == null) {
        returnList = new ReadableOrderList();
    }
    List<ReadableOrder> orders = returnList.getOrders();
    if (!CollectionUtils.isEmpty(orders)) {
        for (ReadableOrder order : orders) {
            order.setCustomer(readableCustomer);
        }
    }
    return returnList;
}
Also used : ReadableOrderList(com.salesmanager.shop.model.order.v0.ReadableOrderList) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Principal(java.security.Principal) ReadableCustomerPopulator(com.salesmanager.shop.populator.customer.ReadableCustomerPopulator) ReadableOrder(com.salesmanager.shop.model.order.v0.ReadableOrder) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with ReadableOrderList

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

the class OrderApi method list.

/**
 * Get a list of orders for a given customer accept request parameter
 * 'start' start index for count accept request parameter 'max' maximum
 * number count, otherwise returns all Used for administrators
 *
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value = { "/private/orders/customers/{id}" }, method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public ReadableOrderList list(@PathVariable final Long id, @RequestParam(value = "start", required = false) Integer start, @RequestParam(value = "count", required = false) Integer count, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) throws Exception {
    Customer customer = customerService.getById(id);
    if (customer == null) {
        LOGGER.error("Customer is null for id " + id);
        response.sendError(404, "Customer is null for id " + id);
        return null;
    }
    if (start == null) {
        start = new Integer(0);
    }
    if (count == null) {
        count = new Integer(100);
    }
    ReadableCustomer readableCustomer = new ReadableCustomer();
    ReadableCustomerPopulator customerPopulator = new ReadableCustomerPopulator();
    customerPopulator.populate(customer, readableCustomer, merchantStore, language);
    ReadableOrderList returnList = orderFacade.getReadableOrderList(merchantStore, customer, start, count, language);
    List<ReadableOrder> orders = returnList.getOrders();
    if (!CollectionUtils.isEmpty(orders)) {
        for (ReadableOrder order : orders) {
            order.setCustomer(readableCustomer);
        }
    }
    return returnList;
}
Also used : ReadableOrderList(com.salesmanager.shop.model.order.v0.ReadableOrderList) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) ReadableCustomerPopulator(com.salesmanager.shop.populator.customer.ReadableCustomerPopulator) ReadableOrder(com.salesmanager.shop.model.order.v0.ReadableOrder) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with ReadableOrderList

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

the class OrderApi method list.

/**
 * This method returns list of all the orders for a store.This is not
 * bound to any specific stores and will get list of all the orders
 * available for this instance
 *
 * @param start
 * @param count
 * @return List of orders
 * @throws Exception
 */
@RequestMapping(value = { "/private/orders" }, method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public ReadableOrderList list(@RequestParam(value = "count", required = false, defaultValue = DEFAULT_ORDER_LIST_COUNT) Integer count, @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "id", required = false) Long id, @RequestParam(value = "status", required = false) String status, @RequestParam(value = "phone", required = false) String phone, @RequestParam(value = "email", required = false) String email, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
    OrderCriteria orderCriteria = new OrderCriteria();
    orderCriteria.setPageSize(count);
    orderCriteria.setStartPage(page);
    orderCriteria.setCustomerName(name);
    orderCriteria.setCustomerPhone(phone);
    orderCriteria.setStatus(status);
    orderCriteria.setEmail(email);
    orderCriteria.setId(id);
    String user = authorizationUtils.authenticatedUser();
    authorizationUtils.authorizeUser(user, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_ORDER, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()), merchantStore);
    ReadableOrderList orders = orderFacade.getReadableOrderList(orderCriteria, merchantStore);
    return orders;
}
Also used : ReadableOrderList(com.salesmanager.shop.model.order.v0.ReadableOrderList) OrderCriteria(com.salesmanager.core.model.order.OrderCriteria) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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