Subversion Repositories SmartDukaan

Rev

Rev 34248 | Rev 34287 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34248 Rev 34259
Line 341... Line 341...
341
    @RequestMapping(value = "/store/resetPassword", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
341
    @RequestMapping(value = "/store/resetPassword", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
342
    public ResponseEntity<?> resetPassword(@RequestBody UserModel userModel) throws Exception {
342
    public ResponseEntity<?> resetPassword(@RequestBody UserModel userModel) throws Exception {
343
        if ((userModel.getMobile() == null || userModel.getMobile().isEmpty()) && (userModel.getPassword() == null || userModel.getPassword().isEmpty())) {
343
        if ((userModel.getMobile() == null || userModel.getMobile().isEmpty()) && (userModel.getPassword() == null || userModel.getPassword().isEmpty())) {
344
            throw new ProfitMandiBusinessException("error", "", "all field are required");
344
            throw new ProfitMandiBusinessException("error", "", "all field are required");
345
        }
345
        }
346
            try{
346
        try {
347
                customerService.resetPassword(userModel.getMobile(), userModel.getPassword());
347
            customerService.resetPassword(userModel.getMobile(), userModel.getPassword());
348
            }
-
 
349
            catch (ProfitMandiBusinessException p){
348
        } catch (ProfitMandiBusinessException p) {
350
                throw new ProfitMandiBusinessException("error", "", "An error occurred while resetting password");
349
            throw new ProfitMandiBusinessException("error", "", "An error occurred while resetting password");
351
            }
350
        }
352
 
351
 
353
        return responseSender.ok(true);
352
        return responseSender.ok(true);
354
    }
353
    }
355
 
354
 
356
    @RequestMapping(value = "/store/changePassword", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
355
    @RequestMapping(value = "/store/changePassword", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
357
    public ResponseEntity<?> changePassword(@RequestBody UserModel userModel) throws Exception {
356
    public ResponseEntity<?> changePassword(@RequestBody UserModel userModel) throws Exception {
358
        logger.info("UserModel - "+userModel);
357
        logger.info("UserModel - " + userModel);
359
        if ((userModel.getOldPassword() == null || userModel.getOldPassword().isEmpty()) && (userModel.getMobile() == null || userModel.getMobile().isEmpty()) &&( userModel.getPassword() == null || userModel.getPassword().isEmpty())) {
358
        if ((userModel.getOldPassword() == null || userModel.getOldPassword().isEmpty()) && (userModel.getMobile() == null || userModel.getMobile().isEmpty()) && (userModel.getPassword() == null || userModel.getPassword().isEmpty())) {
360
            throw new ProfitMandiBusinessException("error", "", "all fields are required");
359
            throw new ProfitMandiBusinessException("error", "", "all fields are required");
361
        }
360
        }
362
        try{
361
        try {
363
            customerService.changePassword(userModel.getMobile(),  userModel.getOldPassword(),userModel.getPassword());
362
            customerService.changePassword(userModel.getMobile(), userModel.getOldPassword(), userModel.getPassword());
364
        }
-
 
365
        catch (ProfitMandiBusinessException p){
363
        } catch (ProfitMandiBusinessException p) {
366
            throw new ProfitMandiBusinessException("error", "", "An error occurred while changing password");
364
            throw new ProfitMandiBusinessException("error", "", "An error occurred while changing password");
367
        }
365
        }
368
        return responseSender.ok(true);
366
        return responseSender.ok(true);
369
    }
367
    }
370
 
368
 
Line 533... Line 531...
533
    @RequestMapping(value = "/store/address/defaultAddress/{addressId}/{customerId}", method = RequestMethod.POST)
531
    @RequestMapping(value = "/store/address/defaultAddress/{addressId}/{customerId}", method = RequestMethod.POST)
534
    @ApiImplicitParams({
532
    @ApiImplicitParams({
535
            @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")
533
            @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")
536
    })
534
    })
537
    @ApiOperation(value = "Set default address for a store")
535
    @ApiOperation(value = "Set default address for a store")
538
    public ResponseEntity<?> setDefaultAddress(HttpServletRequest request,@PathVariable int addressId, @PathVariable int customerId) throws Exception {
536
    public ResponseEntity<?> setDefaultAddress(HttpServletRequest request, @PathVariable int addressId, @PathVariable int customerId) throws Exception {
539
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
537
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
540
        CustomerAddress defaultAddress;
538
        CustomerAddress defaultAddress;
541
        try {
539
        try {
542
            defaultAddress = customerAddressRepository.selectById(addressId);
540
            defaultAddress = customerAddressRepository.selectById(addressId);
543
        } catch (ProfitMandiBusinessException e) {
541
        } catch (ProfitMandiBusinessException e) {
Line 545... Line 543...
545
        }
543
        }
546
        logger.info("CustomerID: {}", customerId);
544
        logger.info("CustomerID: {}", customerId);
547
        List<CustomerAddress> customerAddresses = customerAddressRepository.selectByActiveCustomerId(customerId);
545
        List<CustomerAddress> customerAddresses = customerAddressRepository.selectByActiveCustomerId(customerId);
548
        logger.info("customerAddresses: {}", customerAddresses);
546
        logger.info("customerAddresses: {}", customerAddresses);
549
        for (CustomerAddress addr : customerAddresses) {
547
        for (CustomerAddress addr : customerAddresses) {
550
            if (addr.getDefault()) {
548
            if (addr.getDefault() ) {
551
                addr.setDefault(false);
549
                addr.setDefault(false);
552
            }
550
            }
553
        }
551
        }
554
        defaultAddress.setDefault(true);
552
        defaultAddress.setDefault(true);
555
        return responseSender.ok("Default address updated successfully.");
553
        return responseSender.ok("Default address updated successfully.");
Line 887... Line 885...
887
            cashback = cashback == null ? 0 : cashback;
885
            cashback = cashback == null ? 0 : cashback;
888
            float itemSellingPrice = tagListing.getMop() - cashback;
886
            float itemSellingPrice = tagListing.getMop() - cashback;
889
            CartItemResponseModel cartItemResponseModel = new CartItemResponseModel();
887
            CartItemResponseModel cartItemResponseModel = new CartItemResponseModel();
890
            cartItemResponseModel.setSellingPrice(cartItem.getSellingPrice());
888
            cartItemResponseModel.setSellingPrice(cartItem.getSellingPrice());
891
            cartItemResponseModel.setPendingOrderItemPolicyPlan(cartItem.getPendingOrderItemPolicyPlan());
889
            cartItemResponseModel.setPendingOrderItemPolicyPlan(cartItem.getPendingOrderItemPolicyPlan());
892
            logger.info("itemSellingPrice: {}",itemSellingPrice);
890
            logger.info("itemSellingPrice: {}", itemSellingPrice);
893
            logger.info("cartItem: {}",cartItem.getSellingPrice());
891
            logger.info("cartItem: {}", cartItem.getSellingPrice());
894
            logger.info("cashback: {}",cashback);
892
            logger.info("cashback: {}", cashback);
895
            if (itemSellingPrice != cartItem.getSellingPrice()) {
893
            if (itemSellingPrice != cartItem.getSellingPrice()) {
896
                itemMsg.setType("price");
894
                itemMsg.setType("price");
897
                itemMsg.setMessageText("Price has changed to "+itemSellingPrice);
895
                itemMsg.setMessageText("Price has changed to " + itemSellingPrice);
898
                cartItemResponseModel.setSellingPrice(itemSellingPrice);
896
                cartItemResponseModel.setSellingPrice(itemSellingPrice);
899
                cartMessageChanged++;
897
                cartMessageChanged++;
900
            }
898
            }
901
            int estimate = -2;
899
            int estimate = -2;
902
            LocalDateTime promiseDeliveryTime = LocalDateTime.now();
900
            LocalDateTime promiseDeliveryTime = LocalDateTime.now();
903
            int qtyRequired = (int) cartItem.getQuantity();
901
            int qtyRequired = (int) cartItem.getQuantity();
904
            AvailabilityModel availabilityModel = inventoryItemAvailabilityMap.get(cartItem.getItemId());
902
            AvailabilityModel availabilityModel = inventoryItemAvailabilityMap.get(cartItem.getItemId());
905
            cartItemResponseModel.setMaxQuantity(availabilityModel.getMaxAvailability());
903
            cartItemResponseModel.setMaxQuantity(availabilityModel.getMaxAvailability());
906
            if (availabilityModel.getStoreAvailability() >= qtyRequired) {
904
            if (availabilityModel.getStoreAvailability() >= qtyRequired) {
907
                itemMsg.setType("estimate0");
905
                itemMsg.setType("estimate0");
908
                itemMsg.setMessageText("Store availability is "+ availabilityModel.getStoreAvailability());
906
                itemMsg.setMessageText("Store availability is " + availabilityModel.getStoreAvailability());
909
                estimate = 0;
907
                estimate = 0;
910
            } else if (availabilityModel.getWarehouseAvailability() >= qtyRequired) {
908
            } else if (availabilityModel.getWarehouseAvailability() >= qtyRequired) {
911
                itemMsg.setType("estimate2");
909
                itemMsg.setType("estimate2");
912
                itemMsg.setMessageText("Store availability is "+ availabilityModel.getWarehouseAvailability());
910
                itemMsg.setMessageText("Store availability is " + availabilityModel.getWarehouseAvailability());
913
                estimate = 2;
911
                estimate = 2;
914
            } else if (availabilityModel.getStoreAvailability() > 0) {
912
            } else if (availabilityModel.getStoreAvailability() > 0) {
915
                estimate = 0;
913
                estimate = 0;
916
                qtyRequired = availabilityModel.getStoreAvailability();
914
                qtyRequired = availabilityModel.getStoreAvailability();
917
                cartMessageChanged++;
915
                cartMessageChanged++;
918
                itemMsg.setType("quantity0");
916
                itemMsg.setType("quantity0");
919
                itemMsg.setMessageText("quantity is updated "+qtyRequired);
917
                itemMsg.setMessageText("quantity is updated " + qtyRequired);
920
            } else if (availabilityModel.getWarehouseAvailability() > 0) {
918
            } else if (availabilityModel.getWarehouseAvailability() > 0) {
921
                qtyRequired = availabilityModel.getWarehouseAvailability();
919
                qtyRequired = availabilityModel.getWarehouseAvailability();
922
                estimate = 2;
920
                estimate = 2;
923
                cartMessageChanged++;
921
                cartMessageChanged++;
924
                itemMsg.setType("quantity2");
922
                itemMsg.setType("quantity2");
925
                itemMsg.setMessageText("quantity is updated "+qtyRequired);
923
                itemMsg.setMessageText("quantity is updated " + qtyRequired);
926
            } else {
924
            } else {
927
                qtyRequired = 0;
925
                qtyRequired = 0;
928
                cartMessageChanged++;
926
                cartMessageChanged++;
929
                itemMsg.setType("item");
927
                itemMsg.setType("item");
930
                itemMsg.setMessageText(item.getItemDescriptionNoColor() + " is out of stock");
928
                itemMsg.setMessageText(item.getItemDescriptionNoColor() + " is out of stock");
Line 968... Line 966...
968
 
966
 
969
    }
967
    }
970
 
968
 
971
    @RequestMapping(value = "/store/partnerStock", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
969
    @RequestMapping(value = "/store/partnerStock", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
972
    public ResponseEntity<?> partnerStock(HttpServletRequest request, @RequestParam(required = false, defaultValue = "3") String categoryId, @RequestParam int offset,
970
    public ResponseEntity<?> partnerStock(HttpServletRequest request, @RequestParam(required = false, defaultValue = "3") String categoryId, @RequestParam int offset,
973
      @RequestParam int limit, @RequestParam(required = false) String sort, @RequestParam(required = false) String brand,
971
                                          @RequestParam int limit, @RequestParam(required = false) String sort, @RequestParam(required = false) String brand,
974
      @RequestParam(value = "subCategoryId", required = false) int subCategoryId, @RequestParam(required = false) String queryTerm,
972
                                          @RequestParam(value = "subCategoryId", required = false) int subCategoryId, @RequestParam(required = false) String queryTerm,
975
      @RequestParam(required = false) String listing, @RequestParam(required = false, defaultValue = "true") boolean partnerStockOnly) throws Throwable {
973
                                          @RequestParam(required = false) String listing, @RequestParam(required = false, defaultValue = "true") boolean partnerStockOnly) throws Throwable {
976
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
974
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
977
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
975
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
978
        FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
976
        FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
979
        sort = "w" + fs.getWarehouseId() + "_i desc";
977
        sort = "w" + fs.getWarehouseId() + "_i desc";
980
        dealResponse = this.getCatalogResponse(
978
        dealResponse = this.getCatalogResponse(
Line 1102... Line 1100...
1102
        return responseSender.ok(customerAddressRepository.selectByActiveCustomerId(customerId));
1100
        return responseSender.ok(customerAddressRepository.selectByActiveCustomerId(customerId));
1103
    }
1101
    }
1104
 
1102
 
1105
    @RequestMapping(value = "/store/address", method = RequestMethod.POST)
1103
    @RequestMapping(value = "/store/address", method = RequestMethod.POST)
1106
    public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CustomerAddress customerAddress) throws Throwable {
1104
    public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CustomerAddress customerAddress) throws Throwable {
-
 
1105
        List<CustomerAddress> customerAddresses = customerAddressRepository.selectByActiveCustomerId(customerAddress.getCustomerId());
-
 
1106
        if (customerAddresses.isEmpty()) {
-
 
1107
            customerAddress.setDefault(true);
-
 
1108
        } else {
-
 
1109
            customerAddress.setDefault(false);
-
 
1110
        }
1107
        customerAddressRepository.persist(customerAddress);
1111
        customerAddressRepository.persist(customerAddress);
1108
        return responseSender.ok(customerAddress);
1112
        return responseSender.ok(customerAddress);
1109
    }
1113
    }
1110
 
1114
 
1111
    @RequestMapping(value = "/store/deactivateCustomerAddress", method = RequestMethod.POST)
1115
    @RequestMapping(value = "/store/deactivateCustomerAddress", method = RequestMethod.POST)
1112
    public ResponseEntity<?> deactivateAddresss(HttpServletRequest request, @RequestParam int id) throws Throwable {
1116
    public ResponseEntity<?> deactivateAddresss(HttpServletRequest request, @RequestParam int id) throws Throwable {
1113
        CustomerAddress cust = customerAddressRepository.selectById(id);
1117
        CustomerAddress cust = customerAddressRepository.selectById(id);
-
 
1118
        List<CustomerAddress> customerAddresses = customerAddressRepository.selectByCustomerId(cust.getCustomerId());
1114
        cust.setActive(false);
1119
        cust.setActive(false);
-
 
1120
        if(cust.getDefault()){
-
 
1121
            List<CustomerAddress> activeAddresses = customerAddresses.stream()
-
 
1122
                    .filter(a -> a.getActive() && a.getId() != id)
-
 
1123
                    .sorted(Comparator.comparing(CustomerAddress::getUpdateTimestamp).reversed())
-
 
1124
                    .collect(Collectors.toList());
-
 
1125
 
-
 
1126
            if (!activeAddresses.isEmpty()) {
-
 
1127
                CustomerAddress newDefault = activeAddresses.get(0);
-
 
1128
                newDefault.setDefault(true);
-
 
1129
            }
-
 
1130
        }
1115
        return responseSender.ok(cust);
1131
        return responseSender.ok(cust);
1116
    }
1132
    }
1117
 
1133
 
1118
    @RequestMapping(value = "/store/updateCustomer", method = RequestMethod.POST)
1134
    @RequestMapping(value = "/store/updateCustomer", method = RequestMethod.POST)
1119
    public ResponseEntity<?> updateCustomerProfile(HttpServletRequest request, @RequestBody Customer customer) throws Throwable {
1135
    public ResponseEntity<?> updateCustomerProfile(HttpServletRequest request, @RequestBody Customer customer) throws Throwable {