| 22398 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import javax.mail.internet.InternetAddress;
|
|
|
4 |
import javax.mail.internet.MimeMessage;
|
|
|
5 |
import javax.servlet.http.HttpServletRequest;
|
|
|
6 |
|
| 34247 |
aman.kumar |
7 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 34190 |
aman.kumar |
8 |
import com.spice.profitmandi.web.req.ContactUsRequest;
|
| 23568 |
govind |
9 |
import org.apache.logging.log4j.Logger;
|
|
|
10 |
import org.apache.logging.log4j.LogManager;
|
| 22398 |
amit.gupta |
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
12 |
import org.springframework.http.MediaType;
|
|
|
13 |
import org.springframework.http.ResponseEntity;
|
|
|
14 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
15 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 22400 |
amit.gupta |
16 |
import org.springframework.stereotype.Controller;
|
|
|
17 |
import org.springframework.transaction.annotation.Transactional;
|
| 22398 |
amit.gupta |
18 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
19 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
20 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
21 |
|
|
|
22 |
import com.spice.profitmandi.common.model.UserInfo;
|
|
|
23 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 23568 |
govind |
24 |
import com.spice.profitmandi.dao.config.WebDBContextConfigure;
|
| 22398 |
amit.gupta |
25 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
|
|
26 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
27 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
|
|
28 |
import com.spice.profitmandi.web.req.FeedbackRequest;
|
|
|
29 |
|
|
|
30 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
31 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
32 |
|
| 22400 |
amit.gupta |
33 |
@Controller
|
|
|
34 |
@Transactional(rollbackFor=Throwable.class)
|
| 22398 |
amit.gupta |
35 |
public class ContactUsController {
|
|
|
36 |
|
| 23568 |
govind |
37 |
|
|
|
38 |
private static final Logger LOGGER = LogManager.getLogger(ContactUsController.class);
|
| 22398 |
amit.gupta |
39 |
@Autowired
|
| 22931 |
ashik.ali |
40 |
private JavaMailSender mailSender;
|
| 22398 |
amit.gupta |
41 |
|
|
|
42 |
@Autowired
|
| 22931 |
ashik.ali |
43 |
private ResponseSender<?> responseSender;
|
| 22398 |
amit.gupta |
44 |
|
|
|
45 |
@Autowired
|
| 22931 |
ashik.ali |
46 |
private UserRepository userRepository;
|
| 22398 |
amit.gupta |
47 |
|
|
|
48 |
@RequestMapping(value = "/contact-us/feedback" , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
49 |
@ApiImplicitParams({
|
|
|
50 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
51 |
required = true, dataType = "string", paramType = "header")
|
|
|
52 |
})
|
|
|
53 |
public ResponseEntity<?> sendCrmMail(HttpServletRequest request, @RequestBody FeedbackRequest feedbackRequest) throws Throwable {
|
|
|
54 |
UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");
|
|
|
55 |
User user = userRepository.selectById(userInfo.getUserId());
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
59 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
| 22404 |
amit.gupta |
60 |
helper.setSubject("New Contact Us message");
|
| 22398 |
amit.gupta |
61 |
StringBuffer messageText = new StringBuffer();
|
|
|
62 |
messageText.append("User Id : ").append(userInfo.getUserId()).append("\n\n");
|
|
|
63 |
messageText.append("Email : ").append(user.getEmailId()).append("\n\n");
|
|
|
64 |
messageText.append("Mobile : ").append(user.getMobileNumber()).append("\n\n");
|
|
|
65 |
messageText.append("Subject : ").append(feedbackRequest.getSubject()).append("\n\n");
|
|
|
66 |
messageText.append("Message : ").append(feedbackRequest.getMessage());
|
| 22404 |
amit.gupta |
67 |
helper.setText(messageText.toString());
|
| 23452 |
amit.gupta |
68 |
String[] cc = {"neeraj.arya@smartdukaan.com","rahul.kandpal@smartdukaan.com", "ritesh.chauhan@smartdukaan.com", "krishna.kumar@smartdukaan.com"};
|
| 22405 |
amit.gupta |
69 |
//String[] cc = {"amit.gupta@shop2020.in"};
|
| 22398 |
amit.gupta |
70 |
helper.setCc(cc);
|
| 23839 |
amit.gupta |
71 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
|
|
|
72 |
helper.setTo("help@smartdukaan.com");
|
| 22403 |
amit.gupta |
73 |
helper.setFrom(senderAddress);
|
| 22398 |
amit.gupta |
74 |
mailSender.send(message);
|
| 23568 |
govind |
75 |
LOGGER.info("message send Successfully.....");
|
| 22398 |
amit.gupta |
76 |
return responseSender.ok(true);
|
|
|
77 |
}
|
| 34190 |
aman.kumar |
78 |
@RequestMapping(value="/contact-us",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
79 |
@ApiImplicitParams({
|
|
|
80 |
@ApiImplicitParam( name ="Auth-Token",value="Auth-Token",
|
|
|
81 |
required=true, dataType="string", paramType="header")})
|
| 34247 |
aman.kumar |
82 |
public ResponseEntity<?> sendContactMail(HttpServletRequest request, @RequestBody ContactUsRequest contactUsRequest) throws Throwable {
|
|
|
83 |
if ((contactUsRequest.getMobile() == null || contactUsRequest.getMobile().isEmpty()) && (contactUsRequest.getName() == null || contactUsRequest.getName().isEmpty()) && (contactUsRequest.getEmail() == null || contactUsRequest.getEmail().isEmpty())) {
|
|
|
84 |
throw new ProfitMandiBusinessException("error", "", "all field are required");
|
|
|
85 |
}
|
| 34190 |
aman.kumar |
86 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
87 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
|
|
88 |
helper.setSubject("New Contact Us message");
|
|
|
89 |
String emailContent = "<html>"
|
|
|
90 |
+ "<body style='font-family: Arial, sans-serif;'>"
|
|
|
91 |
+ "<h2 style='color: #333;'>New Contact Us Message</h2>"
|
|
|
92 |
+ "<p><strong>Name:</strong> " + contactUsRequest.getName() + "</p>"
|
|
|
93 |
+ "<p><strong>Email:</strong> " + contactUsRequest.getEmail() + "</p>"
|
|
|
94 |
+ "<p><strong>Mobile:</strong> " + contactUsRequest.getMobile() + "</p>"
|
|
|
95 |
+ "<p><strong>Message:</strong></p>"
|
|
|
96 |
+ "<p style='background: #f4f4f4; padding: 10px; border-radius: 5px;'>"
|
|
|
97 |
+ contactUsRequest.getMessage() + "</p>"
|
|
|
98 |
+ "<br>"
|
|
|
99 |
+ "<p style='color: #777;'>This email was sent via the Contact Us form.</p>"
|
|
|
100 |
+ "</body></html>";
|
|
|
101 |
helper.setText(emailContent, true);
|
|
|
102 |
String[] cc={"aman.gupta@smartdukaan.com","vikas.jangra@smartdukaan.com"};
|
|
|
103 |
helper.setCc(cc);
|
| 34264 |
aman.kumar |
104 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", contactUsRequest.getName());
|
| 34190 |
aman.kumar |
105 |
helper.setFrom(senderAddress);
|
|
|
106 |
helper.setReplyTo(contactUsRequest.getEmail());
|
|
|
107 |
helper.setTo("care@smartdukaan.com");
|
|
|
108 |
|
|
|
109 |
mailSender.send(message);
|
|
|
110 |
LOGGER.info("message send Successfully"+message);
|
|
|
111 |
return responseSender.ok(true);
|
|
|
112 |
}
|
|
|
113 |
|
| 22398 |
amit.gupta |
114 |
}
|