Subversion Repositories SmartDukaan

Rev

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

Rev 35469 Rev 35630
Line 441... Line 441...
441
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
441
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
442
    public ResponseEntity<?> getPartners(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId)
442
    public ResponseEntity<?> getPartners(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId)
443
            throws ProfitMandiBusinessException {
443
            throws ProfitMandiBusinessException {
444
 
444
 
445
        AuthUser authUser = authRepository.selectByGmailId(gmailId);
445
        AuthUser authUser = authRepository.selectByGmailId(gmailId);
-
 
446
        if (authUser == null) {
-
 
447
            LOGGER.warn("No auth user found for gmailId: {}", gmailId);
-
 
448
            return responseSender.badRequest("No user found for the provided email");
-
 
449
        }
446
 
450
 
447
        Map<String, Set<String>> storeGuyMap = csService.getAuthUserPartnerEmailMapping();
451
        Map<String, Set<String>> storeGuyMap = csService.getAuthUserPartnerEmailMapping();
448
 
452
 
449
        Set<String> emails = storeGuyMap.get(authUser.getEmailId());
453
        Set<String> emails = storeGuyMap.get(authUser.getEmailId());
450
        LOGGER.info("emails" + emails);
454
        LOGGER.info("emails: {}", emails);
-
 
455
        if (emails == null || emails.isEmpty()) {
-
 
456
            LOGGER.info("No partner emails found for user: {}", gmailId);
-
 
457
            return responseSender.ok(new ArrayList<>());
-
 
458
        }
451
        List<User> users = userRepository.selectAllByEmailIds(new ArrayList<>(emails));
459
        List<User> users = userRepository.selectAllByEmailIds(new ArrayList<>(emails));
452
        List<Partner> partners = new ArrayList<>();
460
        List<Partner> partners = new ArrayList<>();
453
        for (User user : users) {
461
        for (User user : users) {
454
 
-
 
-
 
462
            try {
455
            UserAccount uc = userAccountRepository.selectSaholicByUserId(user.getId());
463
                UserAccount uc = userAccountRepository.selectSaholicByUserId(user.getId());
-
 
464
                if (uc == null) {
-
 
465
                    LOGGER.warn("No user account found for userId: {}", user.getId());
-
 
466
                    continue;
-
 
467
                }
456
            com.spice.profitmandi.dao.entity.user.User userInfo = userUserRepository.selectById(uc.getAccountKey());
468
                com.spice.profitmandi.dao.entity.user.User userInfo = userUserRepository.selectById(uc.getAccountKey());
-
 
469
                if (userInfo == null) {
-
 
470
                    LOGGER.warn("No user info found for accountKey: {}", uc.getAccountKey());
-
 
471
                    continue;
-
 
472
                }
457
            CustomRetailer customRetailer = retailerService.getFofoRetailer(userInfo.getId());
473
                CustomRetailer customRetailer = retailerService.getFofoRetailer(userInfo.getId());
-
 
474
                if (customRetailer == null) {
-
 
475
                    LOGGER.warn("No custom retailer found for userInfoId: {}", userInfo.getId());
-
 
476
                    continue;
-
 
477
                }
458
 
478
 
459
            Partner partner = new Partner();
479
                Partner partner = new Partner();
460
            partner.setBusinessName(customRetailer.getBusinessName());
480
                partner.setBusinessName(customRetailer.getBusinessName());
461
            partner.setPartnerId(customRetailer.getPartnerId());
481
                partner.setPartnerId(customRetailer.getPartnerId());
462
            partner.setCartId(customRetailer.getCartId());
482
                partner.setCartId(customRetailer.getCartId());
463
            partner.setEmail(customRetailer.getEmail());
483
                partner.setEmail(customRetailer.getEmail());
464
            partner.setGstNumber(customRetailer.getGstNumber());
484
                partner.setGstNumber(customRetailer.getGstNumber());
465
            partner.setDisplayName(customRetailer.getDisplayName());
485
                partner.setDisplayName(customRetailer.getDisplayName());
466
            partner.setCity(customRetailer.getAddress().getCity());
486
                partner.setCity(customRetailer.getAddress() != null ? customRetailer.getAddress().getCity() : null);
467
            partner.setUserId(user.getId());
487
                partner.setUserId(user.getId());
468
            partners.add(partner);
488
                partners.add(partner);
-
 
489
            } catch (Exception e) {
-
 
490
                LOGGER.error("Error processing partner for userId: {}", user.getId(), e);
-
 
491
            }
469
        }
492
        }
470
        LOGGER.info("partners" + partners);
493
        LOGGER.info("partners: {}", partners);
471
        return responseSender.ok(partners);
494
        return responseSender.ok(partners);
472
    }
495
    }
473
 
496
 
474
    @RequestMapping(value = "/franchise-first-visit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
497
    @RequestMapping(value = "/franchise-first-visit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
475
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
498
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})