Subversion Repositories SmartDukaan

Rev

Rev 23936 | Rev 23943 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23936 Rev 23942
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;
3
import java.text.MessageFormat;
4
 
-
 
-
 
4
import java.util.List;
5
 
5
 
6
import javax.mail.internet.InternetAddress;
6
import javax.mail.internet.InternetAddress;
7
import javax.mail.internet.MimeMessage;
7
import javax.mail.internet.MimeMessage;
8
import javax.servlet.http.HttpServletRequest;
8
import javax.servlet.http.HttpServletRequest;
9
 
9
 
Line 18... Line 18...
18
import org.springframework.stereotype.Controller;
18
import org.springframework.stereotype.Controller;
19
import org.springframework.transaction.annotation.Transactional;
19
import org.springframework.transaction.annotation.Transactional;
20
import org.springframework.web.bind.annotation.RequestBody;
20
import org.springframework.web.bind.annotation.RequestBody;
21
import org.springframework.web.bind.annotation.RequestMapping;
21
import org.springframework.web.bind.annotation.RequestMapping;
22
import org.springframework.web.bind.annotation.RequestMethod;
22
import org.springframework.web.bind.annotation.RequestMethod;
-
 
23
import org.springframework.web.bind.annotation.RequestParam;
23
 
24
 
24
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
25
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
26
import com.spice.profitmandi.common.model.CustomRetailer;
25
import com.spice.profitmandi.common.model.ProfitMandiConstants;
27
import com.spice.profitmandi.common.model.ProfitMandiConstants;
26
import com.spice.profitmandi.common.web.util.ResponseSender;
28
import com.spice.profitmandi.common.web.util.ResponseSender;
27
import com.spice.profitmandi.dao.entity.dtr.User;
29
import com.spice.profitmandi.dao.entity.dtr.User;
28
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
30
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
29
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
31
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
30
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
32
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
31
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
33
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
32
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
34
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
33
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
35
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
-
 
36
import com.spice.profitmandi.service.user.RetailerService;
34
import com.spice.profitmandi.service.wallet.WalletService;
37
import com.spice.profitmandi.service.wallet.WalletService;
35
import com.spice.profitmandi.web.req.CreateAddMoneyRequest;
38
import com.spice.profitmandi.web.req.CreateAddMoneyRequest;
36
import io.swagger.annotations.ApiImplicitParam;
39
import io.swagger.annotations.ApiImplicitParam;
37
import io.swagger.annotations.ApiImplicitParams;
40
import io.swagger.annotations.ApiImplicitParams;
38
import io.swagger.annotations.ApiOperation;
41
import io.swagger.annotations.ApiOperation;
Line 59... Line 62...
59
	@Qualifier("userRepository")
62
	@Qualifier("userRepository")
60
	private UserRepository userRepository;
63
	private UserRepository userRepository;
61
 
64
 
62
	@Autowired
65
	@Autowired
63
	private UserAccountRepository userAccountRepository;
66
	private UserAccountRepository userAccountRepository;
-
 
67
	
-
 
68
	@Autowired
-
 
69
	private RetailerService retailerService;
-
 
70
 
64
 
71
 
65
	@Autowired
72
	@Autowired
66
	ResponseSender<?> responseSender;
73
	ResponseSender<?> responseSender;
67
 
74
 
68
	@RequestMapping(value = ProfitMandiConstants.URL_MY_WALLET, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
75
	@RequestMapping(value = ProfitMandiConstants.URL_MY_WALLET, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
Line 95... Line 102...
95
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
102
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
96
	public ResponseEntity<?> AddMoneyToWallet(HttpServletRequest request,
103
	public ResponseEntity<?> AddMoneyToWallet(HttpServletRequest request,
97
			@RequestBody CreateAddMoneyRequest createAddMoneyRequest) throws Exception {
104
			@RequestBody CreateAddMoneyRequest createAddMoneyRequest) throws Exception {
98
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
105
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
99
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
106
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
-
 
107
		CustomRetailer customRetailer=retailerService.getFofoRetailer(retailerId);
100
		AddWalletRequest addWalletrequest = new AddWalletRequest();
108
		AddWalletRequest addWalletrequest = new AddWalletRequest();
101
		addWalletrequest.setRetailerId(retailerId);
109
		addWalletrequest.setRetailerId(retailerId);
102
		addWalletrequest.setAmount(createAddMoneyRequest.getAmount());
110
		addWalletrequest.setAmount(createAddMoneyRequest.getAmount());
103
		addWalletrequest.setTransaction_reference(createAddMoneyRequest.getTransaction_reference());
111
		addWalletrequest.setTransaction_reference(createAddMoneyRequest.getTransaction_reference());
104
		addWalletrequest.setStatus(AddWalletRequestStatus.pending);
112
		addWalletrequest.setStatus(AddWalletRequestStatus.pending);
105
		addWalletRequestRepository.persist(addWalletrequest);
113
		addWalletRequestRepository.persist(addWalletrequest);
-
 
114
		log.info("fofoinfo" + customRetailer);
106
		String subject = "Add money to wallet request";
115
		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}",
116
		String messageText = MessageFormat.format("User Id - {0}\n Name -{1}\n Email -{2}\n Reference - {3}\n Amount - Rs.{4} \n link - {5}",
108
				new Integer(addWalletrequest.getRetailerId()), addWalletrequest.getTransaction_reference(),
117
				new Integer(addWalletrequest.getRetailerId()),customRetailer.getBusinessName(),customRetailer.getEmail(), addWalletrequest.getTransaction_reference(),
109
				new Float(addWalletrequest.getAmount()),"http://partners.smartdukaan.com/dashboard");
118
				new Float(addWalletrequest.getAmount()),"http://partners.smartdukaan.com/dashboard");
110
		String email = "neeraj.gupta@smartdukaan.com";
119
		String email = "tejbeer.kaur@shop2020.in";
111
		this.sendMailWithAttachments(email, subject, messageText);
120
		this.sendMailWithAttachments(email, subject, messageText);
112
 
121
 
113
		return responseSender.ok(true);
122
		return responseSender.ok(true);
114
	}
123
	}
115
 
124
 
Line 125... Line 134...
125
		mailSender.send(message);
134
		mailSender.send(message);
126
 
135
 
127
	}
136
	}
128
	
137
	
129
	
138
	
-
 
139
	@RequestMapping(value = ProfitMandiConstants.URL_ADD_MONEY_TO_WALLET_HISTORY, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
140
	@ApiImplicitParams({
-
 
141
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
-
 
142
	public ResponseEntity<?> getAddMoneyToWalletHistory(HttpServletRequest request,@RequestParam(name = "offset", defaultValue = "0") int offset,
-
 
143
			@RequestParam(name = "limit", defaultValue = "10") int limit) throws ProfitMandiBusinessException {
-
 
144
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
-
 
145
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
-
 
146
		List<AddWalletRequest> walletRequest= addWalletRequestRepository.selectByRetailerId(offset, limit, retailerId);
-
 
147
		return  responseSender.ok(walletRequest);
-
 
148
	}
-
 
149
	
-
 
150
	
130
}
151
}
131
152