Subversion Repositories SmartDukaan

Rev

Rev 23568 | Rev 34190 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.web.controller;

import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.HttpServletRequest;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.spice.profitmandi.common.model.UserInfo;
import com.spice.profitmandi.common.web.util.ResponseSender;
import com.spice.profitmandi.dao.config.WebDBContextConfigure;
import com.spice.profitmandi.dao.entity.dtr.User;
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
import com.spice.profitmandi.web.req.FeedbackRequest;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

@Controller
@Transactional(rollbackFor=Throwable.class)
public class ContactUsController {
        
        
        private static final Logger LOGGER = LogManager.getLogger(ContactUsController.class);
        @Autowired
        private JavaMailSender mailSender;
        
        @Autowired
        private ResponseSender<?> responseSender;
        
        @Autowired
        private UserRepository userRepository;
        
    @RequestMapping(value = "/contact-us/feedback" , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
    public ResponseEntity<?> sendCrmMail(HttpServletRequest request, @RequestBody FeedbackRequest feedbackRequest) throws Throwable {
        UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");
        User user = userRepository.selectById(userInfo.getUserId());
        

        MimeMessage message = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message);
        helper.setSubject("New Contact Us message");
        StringBuffer messageText = new StringBuffer();
        messageText.append("User Id : ").append(userInfo.getUserId()).append("\n\n");
        messageText.append("Email : ").append(user.getEmailId()).append("\n\n");
        messageText.append("Mobile : ").append(user.getMobileNumber()).append("\n\n");
        messageText.append("Subject : ").append(feedbackRequest.getSubject()).append("\n\n");
        messageText.append("Message : ").append(feedbackRequest.getMessage());
        helper.setText(messageText.toString());
        String[] cc = {"neeraj.arya@smartdukaan.com","rahul.kandpal@smartdukaan.com", "ritesh.chauhan@smartdukaan.com", "krishna.kumar@smartdukaan.com"};
        //String[] cc = {"amit.gupta@shop2020.in"};
        helper.setCc(cc);
        InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
        helper.setTo("help@smartdukaan.com");
        helper.setFrom(senderAddress);
        mailSender.send(message);
        LOGGER.info("message send Successfully.....");
        return responseSender.ok(true);
    }
}