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