Subversion Repositories SmartDukaan

Rev

Rev 35458 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35458 Rev 35625
Line 626... Line 626...
626
            @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
626
            @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
627
    public ResponseEntity<?> getPartners(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId,
627
    public ResponseEntity<?> getPartners(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId,
628
                                         @RequestParam(value = "offset") int offset, @RequestParam(value = "limit") int limit)
628
                                         @RequestParam(value = "offset") int offset, @RequestParam(value = "limit") int limit)
629
            throws ProfitMandiBusinessException {
629
            throws ProfitMandiBusinessException {
630
        AuthUser authUser = authRepository.selectByGmailId(gmailId);
630
        AuthUser authUser = authRepository.selectByGmailId(gmailId);
-
 
631
        if (authUser == null) {
-
 
632
            LOGGER.warn("No auth user found for gmailId: {}", gmailId);
-
 
633
            return responseSender.badRequest("No user found for the provided email");
-
 
634
        }
631
 
635
 
632
        Map<String, Set<String>> storeGuyMap = csService.getAuthUserPartnerEmailMapping();
636
        Map<String, Set<String>> storeGuyMap = csService.getAuthUserPartnerEmailMapping();
633
 
637
 
634
        Set<String> emails = storeGuyMap.get(authUser.getEmailId().toLowerCase());
638
        Set<String> emails = storeGuyMap.get(authUser.getEmailId().toLowerCase());
635
        LOGGER.info("emails" + emails);
639
        LOGGER.info("emails: {}", emails);
-
 
640
        if (emails == null || emails.isEmpty()) {
-
 
641
            LOGGER.info("No partner emails found for user: {}", gmailId);
-
 
642
            return responseSender.ok(new ArrayList<>());
-
 
643
        }
636
        List<User> users = userRepository.selectAllByEmails(new ArrayList<>(emails), offset, limit);
644
        List<User> users = userRepository.selectAllByEmails(new ArrayList<>(emails), offset, limit);
637
        List<Partner> partners = new ArrayList<>();
645
        List<Partner> partners = new ArrayList<>();
638
        for (User user : users) {
646
        for (User user : users) {
-
 
647
            try {
-
 
648
                UserAccount uc = userAccountRepository.selectSaholicByUserId(user.getId());
-
 
649
                if (uc == null) {
-
 
650
                    LOGGER.warn("No user account found for userId: {}", user.getId());
-
 
651
                    continue;
-
 
652
                }
-
 
653
                com.spice.profitmandi.dao.entity.user.User userInfo = userUserRepository.selectById(uc.getAccountKey());
-
 
654
                if (userInfo == null) {
-
 
655
                    LOGGER.warn("No user info found for accountKey: {}", uc.getAccountKey());
-
 
656
                    continue;
-
 
657
                }
-
 
658
                CustomRetailer customRetailer = retailerService.getFofoRetailer(userInfo.getId());
-
 
659
                if (customRetailer == null) {
-
 
660
                    LOGGER.warn("No custom retailer found for userInfoId: {}", userInfo.getId());
-
 
661
                    continue;
-
 
662
                }
639
 
663
 
640
            UserAccount uc = userAccountRepository.selectSaholicByUserId(user.getId());
-
 
641
            com.spice.profitmandi.dao.entity.user.User userInfo = userUserRepository.selectById(uc.getAccountKey());
-
 
642
            CustomRetailer customRetailer = retailerService.getFofoRetailer(userInfo.getId());
-
 
643
 
-
 
644
            Partner partner = new Partner();
664
                Partner partner = new Partner();
645
            partner.setBusinessName(customRetailer.getBusinessName());
665
                partner.setBusinessName(customRetailer.getBusinessName());
646
            partner.setPartnerId(customRetailer.getPartnerId());
666
                partner.setPartnerId(customRetailer.getPartnerId());
647
            partner.setCartId(customRetailer.getCartId());
667
                partner.setCartId(customRetailer.getCartId());
648
            partner.setEmail(customRetailer.getEmail());
668
                partner.setEmail(customRetailer.getEmail());
649
            partner.setGstNumber(customRetailer.getGstNumber());
669
                partner.setGstNumber(customRetailer.getGstNumber());
650
            partner.setDisplayName(customRetailer.getDisplayName());
670
                partner.setDisplayName(customRetailer.getDisplayName());
651
            partner.setCity(customRetailer.getAddress().getCity());
671
                partner.setCity(customRetailer.getAddress() != null ? customRetailer.getAddress().getCity() : null);
652
            partner.setUserId(user.getId());
672
                partner.setUserId(user.getId());
653
            partners.add(partner);
673
                partners.add(partner);
-
 
674
            } catch (Exception e) {
-
 
675
                LOGGER.error("Error processing partner for userId: {}", user.getId(), e);
-
 
676
            }
654
        }
677
        }
655
        LOGGER.info("partners" + partners);
678
        LOGGER.info("partners: {}", partners);
656
        return responseSender.ok(partners);
679
        return responseSender.ok(partners);
657
    }
680
    }
658
 
681
 
659
    @RequestMapping(value = "/user/refferal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
682
    @RequestMapping(value = "/user/refferal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
660
    @ApiImplicitParams({
683
    @ApiImplicitParams({