| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
2 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 3 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
3 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 4 |
import com.spice.profitmandi.dao.entity.trialUser.TrialOnBoarding;
|
4 |
import com.spice.profitmandi.dao.entity.fofo.TrialForm;
|
| 5 |
import com.spice.profitmandi.dao.repository.trialOnboarding.TrialOnboardingRepository;
|
5 |
import com.spice.profitmandi.dao.repository.trialOnboarding.TrialFormRepository;
|
| 6 |
import com.spice.profitmandi.service.integrations.gstpro.GstProService;
|
6 |
import com.spice.profitmandi.service.integrations.gstpro.GstProService;
|
| 7 |
import com.spice.profitmandi.service.integrations.gstpro.entity.GstDetails;
|
7 |
import com.spice.profitmandi.service.integrations.gstpro.entity.GstDetails;
|
| 8 |
import org.apache.logging.log4j.LogManager;
|
8 |
import org.apache.logging.log4j.LogManager;
|
| 9 |
import org.apache.logging.log4j.Logger;
|
9 |
import org.apache.logging.log4j.Logger;
|
| 10 |
import org.springframework.beans.factory.annotation.Autowired;
|
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
| Line 15... |
Line 15... |
| 15 |
import org.springframework.web.bind.annotation.RequestMethod;
|
15 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 16 |
import org.springframework.web.bind.annotation.RequestParam;
|
16 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 17 |
|
17 |
|
| 18 |
import javax.servlet.http.HttpServletRequest;
|
18 |
import javax.servlet.http.HttpServletRequest;
|
| 19 |
import javax.transaction.Transactional;
|
19 |
import javax.transaction.Transactional;
|
| 20 |
import java.time.LocalDate;
|
- |
|
| 21 |
import java.time.LocalDateTime;
|
20 |
import java.time.LocalDateTime;
|
| 22 |
import java.util.Collections;
|
21 |
import java.util.Collections;
|
| 23 |
import java.util.List;
|
22 |
import java.util.List;
|
| 24 |
|
23 |
|
| 25 |
|
24 |
|
| 26 |
|
25 |
|
| 27 |
@Controller
|
26 |
@Controller
|
| 28 |
@Transactional
|
27 |
@Transactional
|
| 29 |
public class TrialUserController {
|
28 |
public class TrialUserController {
|
| 30 |
private static final Logger logger = LogManager.getLogger(FileUploaderController.class);
|
29 |
private static final Logger logger = LogManager.getLogger(TrialUserController.class);
|
| 31 |
@Autowired
|
30 |
@Autowired
|
| 32 |
GstProService gstProService;
|
31 |
GstProService gstProService;
|
| 33 |
|
32 |
|
| 34 |
@Autowired
|
33 |
@Autowired
|
| 35 |
TrialOnboardingRepository trialOnboardingRepository;
|
34 |
TrialFormRepository trialOnboardingRepository;
|
| 36 |
|
35 |
|
| 37 |
@Autowired
|
36 |
@Autowired
|
| 38 |
ResponseSender responseSender;
|
37 |
ResponseSender responseSender;
|
| 39 |
|
38 |
|
| 40 |
private static final Logger LOGGER = LogManager.getLogger(DealsController.class);
|
39 |
private static final Logger LOGGER = LogManager.getLogger(DealsController.class);
|
| Line 54... |
Line 53... |
| 54 |
return ResponseEntity.ok(gstDetails);
|
53 |
return ResponseEntity.ok(gstDetails);
|
| 55 |
}
|
54 |
}
|
| 56 |
|
55 |
|
| 57 |
|
56 |
|
| 58 |
@RequestMapping(value = "/trial-registration", method = RequestMethod.POST)
|
57 |
@RequestMapping(value = "/trial-registration", method = RequestMethod.POST)
|
| 59 |
public ResponseEntity<?> createTrialUser(@RequestBody TrialOnBoarding trialOnBoarding) throws Exception {
|
58 |
public ResponseEntity<?> createTrialUser(@RequestBody TrialForm trialForm) {
|
| 60 |
if (trialOnBoarding.getMobile() == null || trialOnBoarding.getMobile().isEmpty()) {
|
59 |
if (trialForm.getMobile() == null || trialForm.getMobile().isEmpty()) {
|
| 61 |
return responseSender.badRequest("Mobile number is required");
|
60 |
return responseSender.badRequest("Mobile number is required");
|
| 62 |
}
|
61 |
}
|
| 63 |
try {
|
62 |
try {
|
| 64 |
TrialOnBoarding existingUser = trialOnboardingRepository.findByMobile(trialOnBoarding.getMobile());
|
63 |
TrialForm existingUser = trialOnboardingRepository.findByMobile(trialForm.getMobile());
|
| 65 |
if (existingUser != null) {
|
64 |
if (existingUser != null) {
|
| 66 |
return responseSender.internalServerError("User already exists");
|
65 |
return responseSender.internalServerError("User already exists");
|
| 67 |
}
|
66 |
}
|
| 68 |
trialOnBoarding.setStatus(ProfitMandiConstants.Status.PENDING);
|
67 |
trialForm.setStatus(ProfitMandiConstants.Status.PENDING);
|
| 69 |
trialOnBoarding.setCreatedOn(LocalDateTime.now());
|
68 |
trialForm.setCreatedOn(LocalDateTime.now());
|
| 70 |
trialOnboardingRepository.persist(trialOnBoarding);
|
69 |
trialOnboardingRepository.persist(trialForm);
|
| 71 |
return responseSender.ok(trialOnBoarding);
|
70 |
return responseSender.ok(trialForm);
|
| 72 |
|
71 |
|
| 73 |
} catch (Exception e) {
|
72 |
} catch (Exception e) {
|
| 74 |
e.printStackTrace();
|
73 |
e.printStackTrace();
|
| 75 |
return responseSender.internalServerError("Registration failed: " + e.getMessage());
|
74 |
return responseSender.internalServerError("Registration failed: " + e.getMessage());
|
| 76 |
}
|
75 |
}
|