| 35275 |
aman |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
3 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 35293 |
amit |
4 |
import com.spice.profitmandi.dao.entity.fofo.TrialForm;
|
|
|
5 |
import com.spice.profitmandi.dao.repository.trialOnboarding.TrialFormRepository;
|
| 35392 |
aman |
6 |
import com.spice.profitmandi.dao.service.TrialService;
|
| 35275 |
aman |
7 |
import com.spice.profitmandi.service.integrations.gstpro.GstProService;
|
|
|
8 |
import com.spice.profitmandi.service.integrations.gstpro.entity.GstDetails;
|
|
|
9 |
import org.apache.logging.log4j.LogManager;
|
|
|
10 |
import org.apache.logging.log4j.Logger;
|
|
|
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
12 |
import org.springframework.http.ResponseEntity;
|
|
|
13 |
import org.springframework.stereotype.Controller;
|
|
|
14 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
15 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
17 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
18 |
|
|
|
19 |
import javax.servlet.http.HttpServletRequest;
|
|
|
20 |
import javax.transaction.Transactional;
|
|
|
21 |
import java.time.LocalDateTime;
|
|
|
22 |
import java.util.Collections;
|
|
|
23 |
import java.util.List;
|
| 35392 |
aman |
24 |
import java.util.Map;
|
| 35275 |
aman |
25 |
|
|
|
26 |
|
|
|
27 |
@Controller
|
|
|
28 |
@Transactional
|
|
|
29 |
public class TrialUserController {
|
| 35293 |
amit |
30 |
private static final Logger logger = LogManager.getLogger(TrialUserController.class);
|
| 35275 |
aman |
31 |
@Autowired
|
|
|
32 |
GstProService gstProService;
|
|
|
33 |
|
|
|
34 |
@Autowired
|
| 35293 |
amit |
35 |
TrialFormRepository trialOnboardingRepository;
|
| 35275 |
aman |
36 |
|
|
|
37 |
@Autowired
|
|
|
38 |
ResponseSender responseSender;
|
|
|
39 |
|
| 35392 |
aman |
40 |
|
|
|
41 |
@Autowired
|
|
|
42 |
TrialService trialService;
|
|
|
43 |
|
| 35275 |
aman |
44 |
private static final Logger LOGGER = LogManager.getLogger(DealsController.class);
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
@RequestMapping(value = "/gstValidate", method = RequestMethod.GET)
|
|
|
48 |
public ResponseEntity<?> gstValidate(HttpServletRequest request, @RequestParam String gstNo) throws Exception {
|
|
|
49 |
LOGGER.info("gstNo -" + gstNo);
|
|
|
50 |
GstDetails gstDetails = gstProService.getGstDetails(gstNo);
|
|
|
51 |
LOGGER.info("gstDetails -" + gstDetails);
|
|
|
52 |
if (gstDetails != null) {
|
|
|
53 |
List<GstDetails.Pradr> adadr = gstDetails.getAdadr();
|
|
|
54 |
adadr.add(gstDetails.getPradr());
|
|
|
55 |
Collections.reverse(adadr);
|
|
|
56 |
LOGGER.info("list_of_adadr-" + adadr);
|
|
|
57 |
}
|
|
|
58 |
return ResponseEntity.ok(gstDetails);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
@RequestMapping(value = "/trial-registration", method = RequestMethod.POST)
|
| 35353 |
amit |
63 |
public ResponseEntity<?> createTrialUser(@RequestBody TrialForm trialForm) {
|
| 35293 |
amit |
64 |
if (trialForm.getMobile() == null || trialForm.getMobile().isEmpty()) {
|
| 35275 |
aman |
65 |
return responseSender.badRequest("Mobile number is required");
|
|
|
66 |
}
|
|
|
67 |
try {
|
| 35293 |
amit |
68 |
TrialForm existingUser = trialOnboardingRepository.findByMobile(trialForm.getMobile());
|
| 35275 |
aman |
69 |
if (existingUser != null) {
|
| 35392 |
aman |
70 |
return responseSender.badRequest("User already exists");
|
| 35275 |
aman |
71 |
}
|
| 35293 |
amit |
72 |
trialForm.setStatus(ProfitMandiConstants.Status.PENDING);
|
|
|
73 |
trialForm.setCreatedOn(LocalDateTime.now());
|
|
|
74 |
trialOnboardingRepository.persist(trialForm);
|
| 35392 |
aman |
75 |
trialService.sentMailToTrialUser(trialForm);
|
|
|
76 |
trialService.sentMailForTrialUser(trialForm);
|
| 35293 |
amit |
77 |
return responseSender.ok(trialForm);
|
| 35275 |
aman |
78 |
|
|
|
79 |
} catch (Exception e) {
|
|
|
80 |
e.printStackTrace();
|
|
|
81 |
return responseSender.internalServerError("Registration failed: " + e.getMessage());
|
|
|
82 |
}
|
|
|
83 |
}
|
| 35392 |
aman |
84 |
@RequestMapping(value = "/trial-consent", method = RequestMethod.POST)
|
|
|
85 |
public ResponseEntity<?> consent(@RequestBody Map<String, String> request) throws Exception {
|
|
|
86 |
String email = request.get("email");
|
|
|
87 |
TrialForm trialForm= trialOnboardingRepository.selectByEmailOrMobile(email);
|
|
|
88 |
trialService.sendInternalFranchiseUpgradeMail(trialForm);
|
|
|
89 |
trialService.sendUpgradeRequestMail(trialForm);
|
|
|
90 |
return responseSender.ok("We have sent upgrade mail successfully");
|
|
|
91 |
}
|
| 35275 |
aman |
92 |
|
|
|
93 |
}
|