| 21532 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 23936 |
tejbeer |
3 |
import java.text.MessageFormat;
|
| 23942 |
tejbeer |
4 |
import java.util.List;
|
| 23936 |
tejbeer |
5 |
|
|
|
6 |
import javax.mail.internet.InternetAddress;
|
|
|
7 |
import javax.mail.internet.MimeMessage;
|
| 21532 |
kshitij.so |
8 |
import javax.servlet.http.HttpServletRequest;
|
|
|
9 |
|
| 23985 |
tejbeer |
10 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
11 |
import org.apache.logging.log4j.Logger;
|
| 21532 |
kshitij.so |
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23936 |
tejbeer |
13 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 21532 |
kshitij.so |
14 |
import org.springframework.http.MediaType;
|
|
|
15 |
import org.springframework.http.ResponseEntity;
|
| 23936 |
tejbeer |
16 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
17 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 21532 |
kshitij.so |
18 |
import org.springframework.stereotype.Controller;
|
| 21702 |
ashik.ali |
19 |
import org.springframework.transaction.annotation.Transactional;
|
| 23936 |
tejbeer |
20 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21532 |
kshitij.so |
21 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
22 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 23942 |
tejbeer |
23 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21532 |
kshitij.so |
24 |
|
|
|
25 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23942 |
tejbeer |
26 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 21532 |
kshitij.so |
27 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22609 |
ashik.ali |
28 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 23936 |
tejbeer |
29 |
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
|
|
|
30 |
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
|
|
|
31 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
|
|
32 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
33 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 22555 |
amit.gupta |
34 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 23942 |
tejbeer |
35 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 22605 |
ashik.ali |
36 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 23936 |
tejbeer |
37 |
import com.spice.profitmandi.web.req.CreateAddMoneyRequest;
|
| 23985 |
tejbeer |
38 |
|
| 21532 |
kshitij.so |
39 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
40 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
41 |
import io.swagger.annotations.ApiOperation;
|
|
|
42 |
|
|
|
43 |
@Controller
|
| 23936 |
tejbeer |
44 |
@Transactional(rollbackFor = Throwable.class)
|
| 21532 |
kshitij.so |
45 |
public class WalletController {
|
|
|
46 |
|
| 23936 |
tejbeer |
47 |
private static final Logger log = LogManager.getLogger(WalletController.class);
|
| 21532 |
kshitij.so |
48 |
|
|
|
49 |
@Autowired
|
| 23037 |
ashik.ali |
50 |
UserWalletRepository userWalletRepository;
|
| 23936 |
tejbeer |
51 |
|
| 21532 |
kshitij.so |
52 |
@Autowired
|
| 23936 |
tejbeer |
53 |
AddWalletRequestRepository addWalletRequestRepository;
|
|
|
54 |
|
|
|
55 |
@Autowired
|
| 23037 |
ashik.ali |
56 |
WalletService walletService;
|
| 23936 |
tejbeer |
57 |
|
| 23037 |
ashik.ali |
58 |
@Autowired
|
| 23936 |
tejbeer |
59 |
JavaMailSender mailSender;
|
|
|
60 |
|
|
|
61 |
@Autowired
|
|
|
62 |
@Qualifier("userRepository")
|
|
|
63 |
private UserRepository userRepository;
|
|
|
64 |
|
|
|
65 |
@Autowired
|
|
|
66 |
private UserAccountRepository userAccountRepository;
|
| 23942 |
tejbeer |
67 |
|
|
|
68 |
@Autowired
|
|
|
69 |
private RetailerService retailerService;
|
| 23936 |
tejbeer |
70 |
|
| 23942 |
tejbeer |
71 |
|
| 23936 |
tejbeer |
72 |
@Autowired
|
| 23037 |
ashik.ali |
73 |
ResponseSender<?> responseSender;
|
|
|
74 |
|
| 23936 |
tejbeer |
75 |
@RequestMapping(value = ProfitMandiConstants.URL_MY_WALLET, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21532 |
kshitij.so |
76 |
@ApiImplicitParams({
|
| 23936 |
tejbeer |
77 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 21532 |
kshitij.so |
78 |
@ApiOperation(value = "")
|
| 23936 |
tejbeer |
79 |
public ResponseEntity<?> getMyWallet(HttpServletRequest request) throws ProfitMandiBusinessException {
|
|
|
80 |
int userId = (int) request.getAttribute("userId");
|
| 24597 |
amit.gupta |
81 |
/*boolean underMaintainance = true;
|
| 24584 |
amit.gupta |
82 |
if(underMaintainance) {
|
|
|
83 |
return responseSender.badRequest(new ProfitMandiBusinessException(null, null, "Wallet is under maintainance, please try after"));
|
| 24597 |
amit.gupta |
84 |
}*/
|
| 23936 |
tejbeer |
85 |
try {
|
| 23037 |
ashik.ali |
86 |
return responseSender.ok(walletService.getUserWalletByUserId(userId));
|
| 23936 |
tejbeer |
87 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23037 |
ashik.ali |
88 |
return responseSender.badRequest(profitMandiBusinessException);
|
|
|
89 |
}
|
| 21532 |
kshitij.so |
90 |
}
|
|
|
91 |
|
| 23936 |
tejbeer |
92 |
@RequestMapping(value = ProfitMandiConstants.URL_MY_WALLET_HISTORY, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21532 |
kshitij.so |
93 |
@ApiImplicitParams({
|
| 23936 |
tejbeer |
94 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
95 |
public ResponseEntity<?> getMyWalletHistory(HttpServletRequest request) throws ProfitMandiBusinessException {
|
| 24597 |
amit.gupta |
96 |
/*boolean underMaintainance = true;
|
| 24584 |
amit.gupta |
97 |
if(underMaintainance) {
|
|
|
98 |
return responseSender.badRequest(new ProfitMandiBusinessException(null, null, "Wallet is under maintainance, please try after"));
|
| 24597 |
amit.gupta |
99 |
}*/
|
| 23936 |
tejbeer |
100 |
int userId = (int) request.getAttribute("userId");
|
|
|
101 |
try {
|
| 23037 |
ashik.ali |
102 |
return responseSender.ok(walletService.getUserWalletHistoryByUserId(userId));
|
| 23936 |
tejbeer |
103 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23037 |
ashik.ali |
104 |
return responseSender.badRequest(profitMandiBusinessException);
|
|
|
105 |
}
|
| 21532 |
kshitij.so |
106 |
}
|
|
|
107 |
|
| 23936 |
tejbeer |
108 |
@RequestMapping(value = ProfitMandiConstants.URL_ADD_MONEY_TO_WALLET, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
109 |
@ApiImplicitParams({
|
|
|
110 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
111 |
public ResponseEntity<?> AddMoneyToWallet(HttpServletRequest request,
|
|
|
112 |
@RequestBody CreateAddMoneyRequest createAddMoneyRequest) throws Exception {
|
|
|
113 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
| 23985 |
tejbeer |
114 |
log.info("user_id"+userId);
|
| 23936 |
tejbeer |
115 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
| 23942 |
tejbeer |
116 |
CustomRetailer customRetailer=retailerService.getFofoRetailer(retailerId);
|
| 23936 |
tejbeer |
117 |
AddWalletRequest addWalletrequest = new AddWalletRequest();
|
|
|
118 |
addWalletrequest.setRetailerId(retailerId);
|
|
|
119 |
addWalletrequest.setAmount(createAddMoneyRequest.getAmount());
|
|
|
120 |
addWalletrequest.setTransaction_reference(createAddMoneyRequest.getTransaction_reference());
|
| 24089 |
tejbeer |
121 |
addWalletrequest.setReference_date(createAddMoneyRequest.getReference_date());
|
| 23936 |
tejbeer |
122 |
addWalletrequest.setStatus(AddWalletRequestStatus.pending);
|
| 24089 |
tejbeer |
123 |
log.info("info"+ addWalletrequest);
|
| 23936 |
tejbeer |
124 |
addWalletRequestRepository.persist(addWalletrequest);
|
| 23942 |
tejbeer |
125 |
log.info("fofoinfo" + customRetailer);
|
| 23936 |
tejbeer |
126 |
String subject = "Add money to wallet request";
|
| 23942 |
tejbeer |
127 |
String messageText = MessageFormat.format("User Id - {0}\n Name -{1}\n Email -{2}\n Reference - {3}\n Amount - Rs.{4} \n link - {5}",
|
|
|
128 |
new Integer(addWalletrequest.getRetailerId()),customRetailer.getBusinessName(),customRetailer.getEmail(), addWalletrequest.getTransaction_reference(),
|
| 23936 |
tejbeer |
129 |
new Float(addWalletrequest.getAmount()),"http://partners.smartdukaan.com/dashboard");
|
| 23943 |
tejbeer |
130 |
String email = "neeraj.gupta@smartdukaan.com";
|
| 23936 |
tejbeer |
131 |
this.sendMailWithAttachments(email, subject, messageText);
|
|
|
132 |
|
|
|
133 |
return responseSender.ok(true);
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
private void sendMailWithAttachments(String email, String subject, String messageText) throws Exception {
|
|
|
137 |
log.info("message" + messageText);
|
|
|
138 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
139 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
140 |
helper.setSubject(subject);
|
|
|
141 |
helper.setText(messageText);
|
|
|
142 |
helper.setTo(email);
|
| 23997 |
tejbeer |
143 |
helper.setCc("neerajgupta2021@gmail.com");
|
| 23936 |
tejbeer |
144 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
|
|
|
145 |
helper.setFrom(senderAddress);
|
|
|
146 |
mailSender.send(message);
|
|
|
147 |
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
|
| 23942 |
tejbeer |
151 |
@RequestMapping(value = ProfitMandiConstants.URL_ADD_MONEY_TO_WALLET_HISTORY, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
152 |
@ApiImplicitParams({
|
|
|
153 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
154 |
public ResponseEntity<?> getAddMoneyToWalletHistory(HttpServletRequest request,@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
155 |
@RequestParam(name = "limit", defaultValue = "10") int limit) throws ProfitMandiBusinessException {
|
|
|
156 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
157 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
|
|
158 |
List<AddWalletRequest> walletRequest= addWalletRequestRepository.selectByRetailerId(offset, limit, retailerId);
|
|
|
159 |
return responseSender.ok(walletRequest);
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
|
| 21532 |
kshitij.so |
163 |
}
|