| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.text.MessageFormat;
|
| - |
|
4 |
|
| - |
|
5 |
|
| - |
|
6 |
import javax.mail.internet.InternetAddress;
|
| - |
|
7 |
import javax.mail.internet.MimeMessage;
|
| 3 |
import javax.servlet.http.HttpServletRequest;
|
8 |
import javax.servlet.http.HttpServletRequest;
|
| 4 |
|
9 |
|
| 5 |
import org.apache.logging.log4j.Logger;
|
10 |
import org.apache.logging.log4j.Logger;
|
| 6 |
import org.apache.logging.log4j.LogManager;
|
11 |
import org.apache.logging.log4j.LogManager;
|
| 7 |
import org.springframework.beans.factory.annotation.Autowired;
|
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
13 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 8 |
import org.springframework.http.MediaType;
|
14 |
import org.springframework.http.MediaType;
|
| 9 |
import org.springframework.http.ResponseEntity;
|
15 |
import org.springframework.http.ResponseEntity;
|
| - |
|
16 |
import org.springframework.mail.javamail.JavaMailSender;
|
| - |
|
17 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 10 |
import org.springframework.stereotype.Controller;
|
18 |
import org.springframework.stereotype.Controller;
|
| 11 |
import org.springframework.transaction.annotation.Transactional;
|
19 |
import org.springframework.transaction.annotation.Transactional;
|
| - |
|
20 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 12 |
import org.springframework.web.bind.annotation.RequestMapping;
|
21 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 13 |
import org.springframework.web.bind.annotation.RequestMethod;
|
22 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 14 |
|
23 |
|
| 15 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
24 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 16 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
25 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 17 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
26 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| - |
|
27 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| - |
|
28 |
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
|
| - |
|
29 |
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
|
| - |
|
30 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
| - |
|
31 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| - |
|
32 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 18 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
33 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 19 |
import com.spice.profitmandi.service.wallet.WalletService;
|
34 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 20 |
|
- |
|
| - |
|
35 |
import com.spice.profitmandi.web.req.CreateAddMoneyRequest;
|
| 21 |
import io.swagger.annotations.ApiImplicitParam;
|
36 |
import io.swagger.annotations.ApiImplicitParam;
|
| 22 |
import io.swagger.annotations.ApiImplicitParams;
|
37 |
import io.swagger.annotations.ApiImplicitParams;
|
| 23 |
import io.swagger.annotations.ApiOperation;
|
38 |
import io.swagger.annotations.ApiOperation;
|
| 24 |
|
39 |
|
| 25 |
@Controller
|
40 |
@Controller
|
| 26 |
@Transactional(rollbackFor=Throwable.class)
|
41 |
@Transactional(rollbackFor = Throwable.class)
|
| 27 |
public class WalletController {
|
42 |
public class WalletController {
|
| 28 |
|
43 |
|
| 29 |
private static final Logger log=LogManager.getLogger(WalletController.class);
|
44 |
private static final Logger log = LogManager.getLogger(WalletController.class);
|
| 30 |
|
45 |
|
| 31 |
@Autowired
|
46 |
@Autowired
|
| 32 |
UserWalletRepository userWalletRepository;
|
47 |
UserWalletRepository userWalletRepository;
|
| - |
|
48 |
|
| - |
|
49 |
@Autowired
|
| - |
|
50 |
AddWalletRequestRepository addWalletRequestRepository;
|
| 33 |
|
51 |
|
| 34 |
@Autowired
|
52 |
@Autowired
|
| 35 |
WalletService walletService;
|
53 |
WalletService walletService;
|
| - |
|
54 |
|
| - |
|
55 |
@Autowired
|
| - |
|
56 |
JavaMailSender mailSender;
|
| 36 |
|
57 |
|
| - |
|
58 |
@Autowired
|
| - |
|
59 |
@Qualifier("userRepository")
|
| - |
|
60 |
private UserRepository userRepository;
|
| - |
|
61 |
|
| - |
|
62 |
@Autowired
|
| - |
|
63 |
private UserAccountRepository userAccountRepository;
|
| - |
|
64 |
|
| 37 |
@Autowired
|
65 |
@Autowired
|
| 38 |
ResponseSender<?> responseSender;
|
66 |
ResponseSender<?> responseSender;
|
| 39 |
|
67 |
|
| 40 |
@RequestMapping(value = ProfitMandiConstants.URL_MY_WALLET, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
68 |
@RequestMapping(value = ProfitMandiConstants.URL_MY_WALLET, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 41 |
@ApiImplicitParams({
|
69 |
@ApiImplicitParams({
|
| 42 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
70 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 43 |
required = true, dataType = "string", paramType = "header")
|
- |
|
| 44 |
})
|
- |
|
| 45 |
@ApiOperation(value = "")
|
71 |
@ApiOperation(value = "")
|
| 46 |
public ResponseEntity<?> getMyWallet(HttpServletRequest request) throws ProfitMandiBusinessException{
|
72 |
public ResponseEntity<?> getMyWallet(HttpServletRequest request) throws ProfitMandiBusinessException {
|
| 47 |
int userId = (int)request.getAttribute("userId");
|
73 |
int userId = (int) request.getAttribute("userId");
|
| 48 |
try{
|
74 |
try {
|
| 49 |
return responseSender.ok(walletService.getUserWalletByUserId(userId));
|
75 |
return responseSender.ok(walletService.getUserWalletByUserId(userId));
|
| 50 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
76 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 51 |
return responseSender.badRequest(profitMandiBusinessException);
|
77 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 52 |
}
|
78 |
}
|
| 53 |
}
|
79 |
}
|
| 54 |
|
80 |
|
| 55 |
@RequestMapping(value = ProfitMandiConstants.URL_MY_WALLET_HISTORY, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
81 |
@RequestMapping(value = ProfitMandiConstants.URL_MY_WALLET_HISTORY, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 56 |
@ApiImplicitParams({
|
82 |
@ApiImplicitParams({
|
| 57 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
83 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 58 |
required = true, dataType = "string", paramType = "header")
|
- |
|
| 59 |
})
|
- |
|
| 60 |
public ResponseEntity<?> getMyWalletHistory(HttpServletRequest request) throws ProfitMandiBusinessException{
|
84 |
public ResponseEntity<?> getMyWalletHistory(HttpServletRequest request) throws ProfitMandiBusinessException {
|
| 61 |
int userId = (int)request.getAttribute("userId");
|
85 |
int userId = (int) request.getAttribute("userId");
|
| 62 |
try{
|
86 |
try {
|
| 63 |
return responseSender.ok(walletService.getUserWalletHistoryByUserId(userId));
|
87 |
return responseSender.ok(walletService.getUserWalletHistoryByUserId(userId));
|
| 64 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
88 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 65 |
return responseSender.badRequest(profitMandiBusinessException);
|
89 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 66 |
}
|
90 |
}
|
| 67 |
}
|
91 |
}
|
| 68 |
|
92 |
|
| - |
|
93 |
@RequestMapping(value = ProfitMandiConstants.URL_ADD_MONEY_TO_WALLET, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| - |
|
94 |
@ApiImplicitParams({
|
| - |
|
95 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| - |
|
96 |
public ResponseEntity<?> AddMoneyToWallet(HttpServletRequest request,
|
| - |
|
97 |
@RequestBody CreateAddMoneyRequest createAddMoneyRequest) throws Exception {
|
| - |
|
98 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
| - |
|
99 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
| - |
|
100 |
AddWalletRequest addWalletrequest = new AddWalletRequest();
|
| - |
|
101 |
addWalletrequest.setRetailerId(retailerId);
|
| - |
|
102 |
addWalletrequest.setAmount(createAddMoneyRequest.getAmount());
|
| - |
|
103 |
addWalletrequest.setTransaction_reference(createAddMoneyRequest.getTransaction_reference());
|
| - |
|
104 |
addWalletrequest.setStatus(AddWalletRequestStatus.pending);
|
| - |
|
105 |
addWalletRequestRepository.persist(addWalletrequest);
|
| - |
|
106 |
String subject = "Add money to wallet request";
|
| - |
|
107 |
String messageText = MessageFormat.format("User Id - {0}\n Reference - {1}\n Amount - Rs.{2} \n link - {3}",
|
| - |
|
108 |
new Integer(addWalletrequest.getRetailerId()), addWalletrequest.getTransaction_reference(),
|
| - |
|
109 |
new Float(addWalletrequest.getAmount()),"http://partners.smartdukaan.com/dashboard");
|
| - |
|
110 |
String email = "neeraj.gupta@smartdukaan.com";
|
| - |
|
111 |
this.sendMailWithAttachments(email, subject, messageText);
|
| - |
|
112 |
|
| - |
|
113 |
return responseSender.ok(true);
|
| - |
|
114 |
}
|
| - |
|
115 |
|
| - |
|
116 |
private void sendMailWithAttachments(String email, String subject, String messageText) throws Exception {
|
| - |
|
117 |
log.info("message" + messageText);
|
| - |
|
118 |
MimeMessage message = mailSender.createMimeMessage();
|
| - |
|
119 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| - |
|
120 |
helper.setSubject(subject);
|
| - |
|
121 |
helper.setText(messageText);
|
| - |
|
122 |
helper.setTo(email);
|
| - |
|
123 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
|
| - |
|
124 |
helper.setFrom(senderAddress);
|
| - |
|
125 |
mailSender.send(message);
|
| - |
|
126 |
|
| - |
|
127 |
}
|
| - |
|
128 |
|
| - |
|
129 |
|
| 69 |
}
|
130 |
}
|
| 70 |
|
131 |
|