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