Subversion Repositories SmartDukaan

Rev

Rev 25458 | Rev 25484 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21248 ashik.ali 1
package com.spice.profitmandi.web.controller;
2
 
25300 tejbeer 3
import java.io.IOException;
25483 tejbeer 4
import java.time.LocalDate;
21248 ashik.ali 5
import java.time.LocalDateTime;
25483 tejbeer 6
import java.time.Period;
7
import java.time.Year;
8
import java.time.YearMonth;
21855 amit.gupta 9
import java.util.ArrayList;
25366 tejbeer 10
import java.util.Arrays;
25300 tejbeer 11
import java.util.Base64;
21428 amit.gupta 12
import java.util.HashMap;
23786 amit.gupta 13
import java.util.HashSet;
21855 amit.gupta 14
import java.util.List;
21277 ashik.ali 15
import java.util.Map;
23786 amit.gupta 16
import java.util.Set;
25483 tejbeer 17
import java.util.stream.Collectors;
21248 ashik.ali 18
 
19
import javax.servlet.http.HttpServletRequest;
20
 
25300 tejbeer 21
import org.apache.http.client.ClientProtocolException;
23532 amit.gupta 22
import org.apache.http.conn.HttpHostConnectException;
23786 amit.gupta 23
import org.apache.logging.log4j.LogManager;
23859 ashik.ali 24
import org.apache.logging.log4j.Logger;
21278 ashik.ali 25
import org.springframework.beans.factory.annotation.Autowired;
21414 kshitij.so 26
import org.springframework.beans.factory.annotation.Value;
25366 tejbeer 27
import org.springframework.http.MediaType;
21248 ashik.ali 28
import org.springframework.http.ResponseEntity;
29
import org.springframework.stereotype.Controller;
21702 ashik.ali 30
import org.springframework.transaction.annotation.Transactional;
21366 kshitij.so 31
import org.springframework.web.bind.annotation.RequestBody;
21248 ashik.ali 32
import org.springframework.web.bind.annotation.RequestMapping;
33
import org.springframework.web.bind.annotation.RequestMethod;
34
import org.springframework.web.bind.annotation.RequestParam;
35
 
22015 ashik.ali 36
import com.eclipsesource.json.Json;
21855 amit.gupta 37
import com.eclipsesource.json.JsonArray;
38
import com.eclipsesource.json.JsonObject;
39
import com.eclipsesource.json.JsonValue;
40
import com.google.gson.Gson;
21248 ashik.ali 41
import com.spice.profitmandi.common.ResponseCodeHolder;
21855 amit.gupta 42
import com.spice.profitmandi.common.enumuration.SchemeType;
21248 ashik.ali 43
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
25366 tejbeer 44
import com.spice.profitmandi.common.model.CustomRetailer;
22930 ashik.ali 45
import com.spice.profitmandi.common.model.GoogleLoginRequest;
21248 ashik.ali 46
import com.spice.profitmandi.common.model.ProfitMandiConstants;
22492 amit.gupta 47
import com.spice.profitmandi.common.model.RegisteredUserInfo;
21469 amit.gupta 48
import com.spice.profitmandi.common.model.UserInfo;
21282 ashik.ali 49
import com.spice.profitmandi.common.util.JWTUtil;
21855 amit.gupta 50
import com.spice.profitmandi.common.web.client.RestClient;
21740 ashik.ali 51
import com.spice.profitmandi.common.web.util.ResponseSender;
25366 tejbeer 52
import com.spice.profitmandi.dao.entity.auth.AuthUser;
21735 ashik.ali 53
import com.spice.profitmandi.dao.entity.dtr.Retailer;
23858 ashik.ali 54
import com.spice.profitmandi.dao.entity.dtr.Role;
21735 ashik.ali 55
import com.spice.profitmandi.dao.entity.dtr.User;
25366 tejbeer 56
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
21735 ashik.ali 57
import com.spice.profitmandi.dao.entity.dtr.UserRole;
22355 ashik.ali 58
import com.spice.profitmandi.dao.entity.user.Address;
25458 tejbeer 59
import com.spice.profitmandi.dao.entity.user.Promoter;
60
import com.spice.profitmandi.dao.entity.user.Refferal;
25483 tejbeer 61
import com.spice.profitmandi.dao.enumuration.dtr.RefferalStatus;
21735 ashik.ali 62
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
25483 tejbeer 63
import com.spice.profitmandi.dao.model.DateRangeModel;
21643 ashik.ali 64
import com.spice.profitmandi.dao.model.UserCart;
25366 tejbeer 65
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
25458 tejbeer 66
import com.spice.profitmandi.dao.repository.dtr.RefferalRepository;
21735 ashik.ali 67
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
23786 amit.gupta 68
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
21735 ashik.ali 69
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
70
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
71
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
22355 ashik.ali 72
import com.spice.profitmandi.dao.repository.user.AddressRepository;
25458 tejbeer 73
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
24491 amit.gupta 74
import com.spice.profitmandi.service.AuthService;
23798 amit.gupta 75
import com.spice.profitmandi.service.authentication.RoleManager;
25366 tejbeer 76
import com.spice.profitmandi.service.user.RetailerService;
23787 amit.gupta 77
import com.spice.profitmandi.service.user.UserService;
21469 amit.gupta 78
import com.spice.profitmandi.web.enumuration.UserStatus;
21277 ashik.ali 79
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
25458 tejbeer 80
import com.spice.profitmandi.web.req.CreateAddMoneyRequest;
81
import com.spice.profitmandi.web.req.CreateRefferalRequest;
21366 kshitij.so 82
import com.spice.profitmandi.web.req.UserRequest;
21855 amit.gupta 83
import com.spice.profitmandi.web.res.Notification;
25366 tejbeer 84
import com.spice.profitmandi.web.res.Partner;
21248 ashik.ali 85
 
21469 amit.gupta 86
import io.swagger.annotations.ApiImplicitParam;
87
import io.swagger.annotations.ApiImplicitParams;
88
 
21248 ashik.ali 89
/**
90
 * @author ashikali
91
 *
92
 */
93
@Controller
25366 tejbeer 94
@Transactional(rollbackFor = Throwable.class)
21248 ashik.ali 95
public class UserController {
21469 amit.gupta 96
 
21448 ashik.ali 97
	@Autowired
22930 ashik.ali 98
	private ResponseSender<?> responseSender;
21469 amit.gupta 99
 
23568 govind 100
	private static final Logger LOGGER = LogManager.getLogger(UserController.class);
21469 amit.gupta 101
 
21855 amit.gupta 102
	@Value("${notifications.api.host}")
103
	private String nodeHost;
25366 tejbeer 104
 
21855 amit.gupta 105
	@Value("${notifications.api.port}")
106
	private int nodePort;
107
 
21414 kshitij.so 108
	@Value("${admin.token}")
109
	private String validAdminToken;
21469 amit.gupta 110
 
21278 ashik.ali 111
	@Autowired
22873 ashik.ali 112
	private UserRepository userRepository;
25366 tejbeer 113
 
22355 ashik.ali 114
	@Autowired
22873 ashik.ali 115
	private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
21469 amit.gupta 116
 
21278 ashik.ali 117
	@Autowired
22873 ashik.ali 118
	private RetailerRepository retailerRepository;
21485 amit.gupta 119
 
120
	@Autowired
22873 ashik.ali 121
	private UserRoleRepository userRoleRepository;
21469 amit.gupta 122
 
21426 ashik.ali 123
	@Autowired
22873 ashik.ali 124
	private UserAccountRepository userAccountRepository;
25366 tejbeer 125
 
22355 ashik.ali 126
	@Autowired
24491 amit.gupta 127
	private AuthService authService;
25366 tejbeer 128
 
24491 amit.gupta 129
	@Autowired
22873 ashik.ali 130
	private AddressRepository addressRepository;
21469 amit.gupta 131
 
21426 ashik.ali 132
	@Autowired
22873 ashik.ali 133
	private GoogleLoginProcessor googleLoginProcessor;
21855 amit.gupta 134
 
21784 amit.gupta 135
	@Autowired
22873 ashik.ali 136
	private UserService userService;
25366 tejbeer 137
 
23786 amit.gupta 138
	@Autowired
23858 ashik.ali 139
	private RestClient restClient;
25366 tejbeer 140
 
23858 ashik.ali 141
	@Autowired
23798 amit.gupta 142
	private RoleManager roleManager;
25366 tejbeer 143
 
23786 amit.gupta 144
	@Autowired
145
	private RoleRepository roleRepository;
21469 amit.gupta 146
 
25366 tejbeer 147
	@Autowired
148
	private AuthRepository authRepository;
149
 
150
	@Autowired
151
	private RetailerService retailerService;
152
 
25458 tejbeer 153
	@Autowired
154
	private RefferalRepository refferalRepository;
155
 
156
	@Autowired
157
	private PromoterRepository promoterRepository;
158
 
21469 amit.gupta 159
	@RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, method = RequestMethod.POST)
25366 tejbeer 160
	public ResponseEntity<?> googleLogin(HttpServletRequest request, @RequestBody GoogleLoginRequest googleLoginRequest)
161
			throws ProfitMandiBusinessException {
23698 amit.gupta 162
		LOGGER.info("requested url : " + request.getRequestURL().toString());
24494 amit.gupta 163
		Map<String, Object> resultMap = googleLoginProcessor.process(googleLoginRequest);
164
		LOGGER.info("Response sent is {}", resultMap);
23698 amit.gupta 165
		return responseSender.ok(googleLoginProcessor.process(googleLoginRequest));
21277 ashik.ali 166
	}
21469 amit.gupta 167
 
168
	@RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_IS_EXPIRED, method = RequestMethod.GET)
25366 tejbeer 169
	public ResponseEntity<?> tokenIsExpired(HttpServletRequest request, @RequestParam(name = "token") String token)
170
			throws ProfitMandiBusinessException {
21469 amit.gupta 171
		LOGGER.info("requested url : " + request.getRequestURL().toString());
22930 ashik.ali 172
		return responseSender.ok(JWTUtil.isExpired(token));
21282 ashik.ali 173
	}
21469 amit.gupta 174
 
22355 ashik.ali 175
	@RequestMapping(value = ProfitMandiConstants.URL_USER_DETAIL_BY_TOKEN, method = RequestMethod.GET)
21469 amit.gupta 176
	@ApiImplicitParams({
177
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
178
	public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
179
		Map<String, Object> responseMap = new HashMap<>();
180
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
21483 amit.gupta 181
		User user = null;
21855 amit.gupta 182
		if (userInfo.getUserId() > -1) {
21483 amit.gupta 183
			user = userRepository.selectById(userInfo.getUserId());
25366 tejbeer 184
			if (!(userInfo.getEmail() == null || user.getEmailId().equalsIgnoreCase(userInfo.getEmail()))) {
24491 amit.gupta 185
				String userName = null;
25366 tejbeer 186
				if (user.getSecondryEmailId() != null && user.getSecondryEmailId().equals(userInfo.getEmail())) {
24491 amit.gupta 187
					userName = user.getFirstName() + " " + user.getLastName();
188
				} else {
189
					userName = authService.getNameByEmailId(userInfo.getEmail());
190
				}
191
				responseMap.put(ProfitMandiConstants.USER_ID, userInfo.getUserId());
192
				responseMap.put(ProfitMandiConstants.USER_NAME, userName);
193
				responseMap.put(ProfitMandiConstants.USER_STATUS, "fofoAssociate");
194
				responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
195
				return responseSender.ok(responseMap);
196
			}
21483 amit.gupta 197
		} else {
198
			try {
199
				user = userRepository.selectByEmailId(userInfo.getEmail());
200
			} catch (ProfitMandiBusinessException e1) {
201
			}
25366 tejbeer 202
			if (user == null) {
23204 ashik.ali 203
				try {
204
					user = userRepository.selectBySecondryEmailId(userInfo.getEmail());
205
				} catch (ProfitMandiBusinessException e1) {
206
					LOGGER.info("Uneregistered user", userInfo.getEmail());
207
				}
208
			}
21483 amit.gupta 209
		}
210
		if (user != null) {
23858 ashik.ali 211
			int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
21491 amit.gupta 212
			responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
21526 amit.gupta 213
			responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
22017 amit.gupta 214
			responseMap.put(ProfitMandiConstants.USER_NAME, user.getFirstName() + " " + user.getLastName());
23786 amit.gupta 215
			List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
25366 tejbeer 216
			// LOGGER.info("userRoles {} ", userRoles);
22032 ashik.ali 217
 
218
			// generate new token if roles have been updated
23786 amit.gupta 219
			if (userInfo.getRoleIds() == null || roleIds.size() != userInfo.getRoleIds().size()) {
23858 ashik.ali 220
				String[] roleIdStrings = new String[roleIds.size()];
22603 amit.gupta 221
				int index = 0;
23786 amit.gupta 222
				for (int roleId : roleIds) {
23858 ashik.ali 223
					roleIdStrings[index++] = String.valueOf(roleId);
22603 amit.gupta 224
				}
23858 ashik.ali 225
				String newToken = JWTUtil.create(user.getId(), retailerId, roleIdStrings);
21483 amit.gupta 226
				responseMap.put("newAuthToken", newToken);
227
			}
23858 ashik.ali 228
			// if user is retailer
23786 amit.gupta 229
			Set<Integer> roleIdsSet = new HashSet<Integer>(roleIds);
23858 ashik.ali 230
			if (roleManager.isRetailer(roleIdsSet)) {
22032 ashik.ali 231
				UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
232
				Retailer retailer = retailerRepository.selectById(uc.getUserId());
22370 amit.gupta 233
				com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(uc.getUserId());
25366 tejbeer 234
				if (saholicUser.getAddressId() != null) {
22370 amit.gupta 235
					Address address = addressRepository.selectById(saholicUser.getAddressId());
236
					responseMap.put(ProfitMandiConstants.ADDRESS, address);
237
				}
21485 amit.gupta 238
				// if retailer is activated 1 then verified retailer
239
				// else if migrated is 1 then old retailer
25366 tejbeer 240
				// also lets incoporte old process i.e is user is activated then also retailer
241
				// is verified retailer
21485 amit.gupta 242
				// else retailer is not verifed
22497 amit.gupta 243
				if (retailer.isActive() || user.isActivated()) {
23798 amit.gupta 244
					if (roleManager.isPartner(roleIdsSet)) {
22017 amit.gupta 245
						responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.FOFO.getValue());
246
					} else {
247
						responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.VERIFIED_RETAILER.getValue());
248
					}
22032 ashik.ali 249
				} else if (retailer.isMigrated()) {
21485 amit.gupta 250
					responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.RETAILER.getValue());
21469 amit.gupta 251
				} else {
21485 amit.gupta 252
					responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_VERIFIED_RETAILER.getValue());
21469 amit.gupta 253
				}
23798 amit.gupta 254
			} else if (roleManager.isUser(roleIdsSet)) {
22502 amit.gupta 255
				responseMap.put("userInfo", getRegisteredUserInfo(user));
21469 amit.gupta 256
				responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.REGISTERED.getValue());
22032 ashik.ali 257
			}
21491 amit.gupta 258
		} else {
259
			responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED.getValue());
260
			responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
21469 amit.gupta 261
		}
22032 ashik.ali 262
 
21469 amit.gupta 263
		return responseSender.ok(responseMap);
264
	}
25366 tejbeer 265
 
22502 amit.gupta 266
	private RegisteredUserInfo getRegisteredUserInfo(User user) throws Throwable {
22492 amit.gupta 267
		RegisteredUserInfo ri = new RegisteredUserInfo();
268
		ri.setCity(user.getCity());
269
		ri.setFirstName(user.getFirstName());
270
		ri.setLastName(user.getLastName());
22493 amit.gupta 271
		ri.setPhone(user.getMobileNumber());
22492 amit.gupta 272
		ri.setPinCode(user.getPinCode());
22845 amit.gupta 273
		ri.setState(user.getState());
22492 amit.gupta 274
		return ri;
275
	}
21469 amit.gupta 276
 
277
	@RequestMapping(value = ProfitMandiConstants.URL_USER, method = RequestMethod.POST)
21501 amit.gupta 278
	@ApiImplicitParams({
22032 ashik.ali 279
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
280
	public ResponseEntity<?> createUser(HttpServletRequest request, @RequestBody UserRequest userRequest)
22930 ashik.ali 281
			throws ProfitMandiBusinessException {
21469 amit.gupta 282
		LOGGER.info("requested url : " + request.getRequestURL().toString());
21368 kshitij.so 283
		User user = new User();
284
		user.setFirstName(userRequest.getFirstName());
285
		user.setLastName(userRequest.getLastName());
286
		user.setCity(userRequest.getCity());
287
		user.setPinCode(Integer.valueOf(userRequest.getPinCode()));
22845 amit.gupta 288
		user.setState(userRequest.getState());
21708 amit.gupta 289
		user.setMobileNumber(userRequest.getMobieNumber());
21368 kshitij.so 290
		user.setEmailId(userRequest.getEmailId());
291
		user.setUsername("");
292
		user.setPassword("");
293
		user.setMobile_verified(false);
294
		user.setReferral_url("");
295
		user.setGroup_id(1);
22504 amit.gupta 296
		user.setStatus(1);
21368 kshitij.so 297
		user.setActivated(false);
21501 amit.gupta 298
		user.setCreateTimestamp(LocalDateTime.now());
299
		user.setUpdateTimestamp(LocalDateTime.now());
22930 ashik.ali 300
		userRepository.persist(user);
23858 ashik.ali 301
		Role role = roleRepository.selectByName(RoleType.USER.toString());
22930 ashik.ali 302
		UserRole userRole = new UserRole();
23858 ashik.ali 303
		userRole.setRoleId(role.getId());
22930 ashik.ali 304
		userRole.setUserId(user.getId());
305
		userRoleRepository.persist(userRole);
306
		return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1000"));
25366 tejbeer 307
 
21278 ashik.ali 308
	}
21469 amit.gupta 309
 
310
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ID, method = RequestMethod.GET)
25366 tejbeer 311
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id)
312
			throws ProfitMandiBusinessException {
21469 amit.gupta 313
		LOGGER.info("requested url : " + request.getRequestURL().toString());
22930 ashik.ali 314
		return responseSender.ok(userRepository.selectById(id));
21248 ashik.ali 315
	}
21469 amit.gupta 316
 
317
	@RequestMapping(value = ProfitMandiConstants.URL_USER_MOBILE_NUMBER, method = RequestMethod.GET)
318
	public ResponseEntity<?> getByMobileNumber(HttpServletRequest request,
25366 tejbeer 319
			@RequestParam(name = "mobileNumber") String mobileNumber) throws ProfitMandiBusinessException {
21469 amit.gupta 320
		LOGGER.info("requested url : " + request.getRequestURL().toString());
22930 ashik.ali 321
		return responseSender.ok(userRepository.selectByMobileNumber(mobileNumber));
21248 ashik.ali 322
	}
21469 amit.gupta 323
 
21784 amit.gupta 324
	@ApiImplicitParams({
21501 amit.gupta 325
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
326
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ACTIVATE, method = RequestMethod.POST)
327
	public ResponseEntity<?> activateUser(HttpServletRequest request,
21784 amit.gupta 328
			@RequestParam(name = "activationCode") String activationCode) throws Throwable {
21855 amit.gupta 329
		int userId = (int) request.getAttribute("userId");
21784 amit.gupta 330
		UserCart uc = userAccountRepository.getUserCart(userId);
331
		return responseSender.ok(userService.updateActivation(userId, uc.getUserId(), activationCode));
332
	}
21855 amit.gupta 333
 
25458 tejbeer 334
	/*
335
	 * @ApiImplicitParams({
336
	 * 
337
	 * @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true,
338
	 * dataType = "string", paramType = "header") })
339
	 * 
340
	 * @RequestMapping(value = ProfitMandiConstants.URL_USER_NOTIFICATIONS, method =
341
	 * RequestMethod.GET) public ResponseEntity<?>
342
	 * getNofitications(HttpServletRequest request,
343
	 * 
344
	 * @RequestParam(name = "androidId") String androidId, @RequestParam(name =
345
	 * "pageNumber") int pageNumber,
346
	 * 
347
	 * @RequestParam(name = "pageSize") int pageSize) throws
348
	 * ProfitMandiBusinessException { int userId = (int)
349
	 * request.getAttribute("userId"); String restResponse = null; Map<String,
350
	 * String> params = new HashMap<>();
351
	 * 
352
	 * String uri = "/getAllNotifications"; params.put("user_id", userId + "");
353
	 * params.put("android_id", androidId); params.put("limit", pageSize + "");
354
	 * params.put("offset", "" + ((pageNumber - 1) * pageSize)); try { restResponse
355
	 * = restClient.get(SchemeType.HTTP, nodeHost, nodePort, uri, params); } catch
356
	 * (HttpHostConnectException e) { throw new ProfitMandiBusinessException("", "",
357
	 * "Could not Connect to host"); }
358
	 * 
359
	 * JsonArray result_json = Json.parse(restResponse).asArray();
360
	 * 
361
	 * List<Notification> notifications = new ArrayList<>();
362
	 * 
363
	 * for (JsonValue j : result_json) {
364
	 * notifications.add(toNotifiaction(j.asObject())); }
365
	 * 
366
	 * return responseSender.ok(notifications); }
367
	 * 
368
	 * private Notification toNotifiaction(JsonObject jsonObject) { Notification n =
369
	 * (Notification) (new Gson().fromJson(jsonObject.toString(),
370
	 * Notification.class)); if (n.getStatus().equals("opened") ||
371
	 * n.getStatus().equals("referrer") || n.getStatus().equals("seen")) {
372
	 * n.setSeen(true); } return n; }
373
	 */
21855 amit.gupta 374
 
21426 ashik.ali 375
	@RequestMapping(value = ProfitMandiConstants.URL_USER_IS_EXIST_MOBILE_NUMBER, method = RequestMethod.GET)
21469 amit.gupta 376
	public ResponseEntity<?> isMobileNumberExist(HttpServletRequest request,
377
			@RequestParam(name = "mobileNumber") String mobileNumber) {
378
		LOGGER.info("requested url : " + request.getRequestURL().toString());
21448 ashik.ali 379
		return responseSender.ok(userRepository.isExistByMobileNumber(mobileNumber));
21426 ashik.ali 380
	}
21469 amit.gupta 381
 
382
	@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID, method = RequestMethod.GET)
25366 tejbeer 383
	public ResponseEntity<?> getByEmailId(HttpServletRequest request, @RequestParam(name = "emailId") String emailId)
384
			throws ProfitMandiBusinessException {
21469 amit.gupta 385
		LOGGER.info("requested url : " + request.getRequestURL().toString());
23204 ashik.ali 386
		User user = null;
25366 tejbeer 387
		try {
23204 ashik.ali 388
			user = userRepository.selectByEmailId(emailId);
25366 tejbeer 389
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
23204 ashik.ali 390
			user = userRepository.selectBySecondryEmailId(emailId);
391
		}
392
		return responseSender.ok(user);
21248 ashik.ali 393
	}
21469 amit.gupta 394
 
395
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ALL, method = RequestMethod.GET)
396
	public ResponseEntity<?> getAllRoles(HttpServletRequest request, @RequestParam(name = "id") int id) {
397
		LOGGER.info("requested url : " + request.getRequestURL().toString());
21448 ashik.ali 398
		return responseSender.ok(userRoleRepository.selectRolesByUserId(id));
21248 ashik.ali 399
	}
25366 tejbeer 400
 
23204 ashik.ali 401
	@ApiImplicitParams({
25366 tejbeer 402
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
23204 ashik.ali 403
	@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID_AND_FOFO_STORE_CODE, method = RequestMethod.GET)
25366 tejbeer 404
	public ResponseEntity<?> getSecondryEmailAndStoreCode(HttpServletRequest request)
405
			throws ProfitMandiBusinessException {
23204 ashik.ali 406
		LOGGER.info("requested url : " + request.getRequestURL().toString());
407
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
408
		return responseSender.ok(userService.getEmailsAndFofoStoreCodeByUserId(userId));
409
	}
25366 tejbeer 410
 
23204 ashik.ali 411
	@ApiImplicitParams({
25366 tejbeer 412
			@ApiImplicitParam(name = "Auth-Token", value = "-Token", required = true, dataType = "string", paramType = "header") })
23858 ashik.ali 413
	@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID, method = RequestMethod.PUT)
23204 ashik.ali 414
	public ResponseEntity<?> updateSecondryEmailId(HttpServletRequest request,
25366 tejbeer 415
			@RequestParam(name = ProfitMandiConstants.SECONDRY_EMAIL_ID) String secondryEmailId) throws Throwable {
416
		int userId = (int) request.getAttribute("userId");
417
		User user = userRepository.selectById(userId);
418
		user.setSecondryEmailId(secondryEmailId);
419
		userRepository.persist(user);
420
		return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1001"));
421
	}
21414 kshitij.so 422
 
423
	@RequestMapping(value = ProfitMandiConstants.URL_ADMIN_TOKEN, method = RequestMethod.POST)
21469 amit.gupta 424
	public ResponseEntity<?> getAdminToken(HttpServletRequest request,
425
			@RequestParam(name = "adminToken") String adminToken, @RequestParam(name = "emailId") String emailId) {
426
		LOGGER.info("requested url : " + request.getRequestURL().toString());
427
		if (!adminToken.equals(validAdminToken)) {
22930 ashik.ali 428
			return responseSender.forbidden(null);
21414 kshitij.so 429
		}
21469 amit.gupta 430
 
21414 kshitij.so 431
		Map<String, Object> responseMap = new HashMap<>(2);
23204 ashik.ali 432
		User user = null;
21469 amit.gupta 433
		try {
23204 ashik.ali 434
			user = userRepository.selectByEmailId(emailId);
435
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
25366 tejbeer 436
 
23204 ashik.ali 437
		}
25366 tejbeer 438
 
439
		if (user == null) {
440
			try {
23204 ashik.ali 441
				user = userRepository.selectBySecondryEmailId(emailId);
25366 tejbeer 442
			} catch (ProfitMandiBusinessException profitMandiBusinessException) {
443
 
23204 ashik.ali 444
			}
445
		}
25366 tejbeer 446
		if (user != null) {
23858 ashik.ali 447
			int retailerId = 0;
448
			try {
449
				retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
450
			} catch (ProfitMandiBusinessException e) {
451
				// TODO Auto-generated catch block
452
				e.printStackTrace();
453
			}
454
			List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
455
			String[] roleIdsString = new String[roleIds.size()];
21414 kshitij.so 456
			int index = 0;
23858 ashik.ali 457
			for (int roleId : roleIds) {
458
				roleIdsString[index++] = String.valueOf(roleId);
21414 kshitij.so 459
			}
23858 ashik.ali 460
			responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), retailerId, roleIdsString));
21414 kshitij.so 461
			responseMap.put(ProfitMandiConstants.REGISTERED, true);
25366 tejbeer 462
		} else {
21469 amit.gupta 463
			responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(emailId));
21414 kshitij.so 464
			responseMap.put(ProfitMandiConstants.REGISTERED, false);
465
		}
21448 ashik.ali 466
		return responseSender.ok(responseMap);
21469 amit.gupta 467
 
21414 kshitij.so 468
	}
25366 tejbeer 469
 
25300 tejbeer 470
	@RequestMapping(value = "/mobileappsettings", method = RequestMethod.POST)
25366 tejbeer 471
	public ResponseEntity<?> mobileAppSettings(HttpServletRequest request, @RequestParam(name = "t") int timestamp,
472
			@RequestParam(name = "imeinumber") String imeinumber)
473
			throws ProfitMandiBusinessException, ClientProtocolException, IOException {
474
 
475
		final String uri = "http://api.profittill.com/mobileappsettings?t=" + timestamp + "&imeinumber=" + imeinumber;
25300 tejbeer 476
		final String BASIC_AUTH = "Basic " + Base64.getEncoder().encodeToString("dtr:dtr18Feb2015".getBytes());
477
		Map<String, String> headers = new HashMap<>();
478
		Map<String, String> params = new HashMap<>();
479
		headers.put("Authorization", BASIC_AUTH);
480
		return responseSender.ok(restClient.post(uri, params, headers));
481
	}
22032 ashik.ali 482
 
25366 tejbeer 483
	@RequestMapping(value = "/getPartners", method = RequestMethod.GET)
484
	@ApiImplicitParams({
485
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
486
	public ResponseEntity<?> getPartners(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId,
487
			@RequestParam(value = "offset") int offset, @RequestParam(value = "limit") int limit)
488
			throws ProfitMandiBusinessException {
489
		AuthUser authUser = authRepository.selectByGmailId(gmailId);
490
 
491
		Map<String, List<String>> storeGuyMap = new HashMap<>();
492
		for (Map.Entry<String, List<String>> entry : storeManagerMap.entrySet()) {
493
			String storeEmail = entry.getKey();
494
			List<String> storeGuys = entry.getValue();
495
			for (String storeGuy : storeGuys) {
496
				if (!storeGuyMap.containsKey(storeGuy)) {
497
					storeGuyMap.put(storeGuy, new ArrayList<>());
498
				}
499
				storeGuyMap.get(storeGuy).add(storeEmail);
500
			}
501
 
502
		}
503
		storeGuyMap.remove("");
504
 
25483 tejbeer 505
		List<String> emails = storeGuyMap.get(authUser.getEmailId().toLowerCase());
25366 tejbeer 506
		LOGGER.info("emails" + emails);
25458 tejbeer 507
		List<User> users = userRepository.selectAllByEmails(emails, offset, limit);
25366 tejbeer 508
		List<Partner> partners = new ArrayList<>();
509
		for (User user : users) {
25458 tejbeer 510
 
25366 tejbeer 511
			UserAccount uc = userAccountRepository.selectSaholicByUserId(user.getId());
25458 tejbeer 512
			com.spice.profitmandi.dao.entity.user.User userInfo = userUserRepository.selectById(uc.getAccountKey());
25366 tejbeer 513
			CustomRetailer customRetailer = retailerService.getFofoRetailer(userInfo.getId());
514
 
515
			Partner partner = new Partner();
516
			partner.setBusinessName(customRetailer.getBusinessName());
517
			partner.setPartnerId(customRetailer.getPartnerId());
518
			partner.setCartId(customRetailer.getCartId());
519
			partner.setEmail(customRetailer.getEmail());
520
			partner.setGstNumber(customRetailer.getGstNumber());
521
			partner.setDisplayName(customRetailer.getDisplayName());
522
			partner.setCity(customRetailer.getAddress().getCity());
523
			partner.setUserId(user.getId());
524
			partners.add(partner);
525
		}
526
		LOGGER.info("partners" + partners);
527
		return responseSender.ok(partners);
528
	}
529
 
530
	public static final Map<String, String> nameEmail = new HashMap<>();
531
 
532
	public static final Map<String, List<String>> storeManagerMap = new HashMap<>();
533
 
534
	static {
535
		nameEmail.put("Amod", "amod.sen@smartdukaan.com");
536
		nameEmail.put("Parmod", "parmod.kumar@smartdukaan.com");
537
		nameEmail.put("Anis", "md.anis@smartdukaan.com");
538
		nameEmail.put("Manoj", "manoj.singh@smartdukaan.com");
539
		nameEmail.put("Adeel", "adeel.yazdani@smartdukaan.com");
540
		nameEmail.put("Mohinder", "mohinder.mutreja@smartdukaan.com");
541
		nameEmail.put("Dharmendar", "dharmender.verma@smartdukaan.com");
542
		nameEmail.put("Rajat", "rajat.gupta@smartdukaan.com");
543
		nameEmail.put("Ankit", "ankit.bhatia@smartdukaan.com");
544
		nameEmail.put("Rajit", "rajit.alag@smartdukaan.com");
545
		nameEmail.put("Gulshan", "gulshan.kumar@smartdukaan.com");
546
		nameEmail.put("PramodSharma", "parmod.sharma@smartdukaan.com");
547
		// nameEmail.put("Gulshan","");
25458 tejbeer 548
		storeManagerMap.put("themobileplanet03@gmail.com",
549
				Arrays.asList("amod.sen@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
550
		storeManagerMap.put("mobileplanet7599@gmail.com", Arrays.asList("parmod.sharma@smartdukaan.com",
551
				"dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
552
		storeManagerMap.put("robintelecom.snp@gmail.com", Arrays.asList("parmod.sharma@smartdukaan.com",
553
				"dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
554
		storeManagerMap.put("smartconnect4141@gmail.com",
555
				Arrays.asList("amod.sen@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
556
		storeManagerMap.put("bhimsain919@gmail.com", Arrays.asList("parmod.sharma@smartdukaan.com",
557
				"dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
558
		storeManagerMap.put("babitaranirk@gmail.com",
559
				Arrays.asList("parmod.sharma@smartdukaan.com", "", "mohinder.mutreja@smartdukaan.com"));
560
		storeManagerMap.put("dharmendery079@gmail.com",
561
				Arrays.asList("manoj.singh@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
562
		storeManagerMap.put("kkv.enterprises1@gmail.com",
563
				Arrays.asList("parmod.sharma@smartdukaan.com", "", "mohinder.mutreja@smartdukaan.com"));
564
		storeManagerMap.put("gulshersaifi74226@gmail.com",
565
				Arrays.asList("amod.sen@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
566
		storeManagerMap.put("deepak.lalwani1985@gmail.com",
567
				Arrays.asList("manoj.singh@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
568
		storeManagerMap.put("gupta.smartdukaan@gmail.com",
569
				Arrays.asList("amod.sen@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
570
		storeManagerMap.put("sachinindri2006@gmail.com", Arrays.asList("parmod.sharma@smartdukaan.com",
571
				"dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
572
		storeManagerMap.put("kambojanil83@gmail.com",
573
				Arrays.asList("parmod.sharma@smartdukaan.com", "", "mohinder.mutreja@smartdukaan.com"));
574
		storeManagerMap.put("uppal.neeraj82@gmail.com",
575
				Arrays.asList("", "ankit.bhatia@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
576
		storeManagerMap.put("thefonehousekarnal@gmail.com", Arrays.asList("parmod.sharma@smartdukaan.com",
577
				"dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
578
		storeManagerMap.put("richa9910763006@gmail.com",
579
				Arrays.asList("manoj.singh@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
580
		storeManagerMap.put("smartdukangzb@gmail.com",
581
				Arrays.asList("manoj.singh@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
582
		storeManagerMap.put("lovelymobile183@gmail.com",
583
				Arrays.asList("manoj.singh@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
584
		storeManagerMap.put("smartdukaan.sonepat@gmail.com", Arrays.asList("parmod.sharma@smartdukaan.com",
585
				"dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
586
		storeManagerMap.put("arunmittal299@gmail.com", Arrays.asList("parmod.sharma@smartdukaan.com",
587
				"dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
588
		storeManagerMap.put("gtc01100@gmail.com", Arrays.asList("parmod.sharma@smartdukaan.com",
589
				"dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
590
		storeManagerMap.put("sumittyagi1975@gmail.com",
591
				Arrays.asList("manoj.singh@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
592
		storeManagerMap.put("metrofurniture342@gmail.com", Arrays.asList("parmod.sharma@smartdukaan.com",
593
				"dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
594
		storeManagerMap.put("suryaelectronicskaithal@gmail.com",
595
				Arrays.asList("Parmod", "", "mohinder.mutreja@smartdukaan.com"));
596
		storeManagerMap.put("mmtelecomsec16@gmail.com",
597
				Arrays.asList("amod.sen@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
598
		storeManagerMap.put("omsonsindia08@gmail.com", Arrays.asList("parmod.sharma@smartdukaan.com",
599
				"dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
600
		storeManagerMap.put("smartenterprisespv@gmail.com",
601
				Arrays.asList("amod.sen@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
602
		storeManagerMap.put("cachaitnya@gmail.com",
603
				Arrays.asList("amod.sen@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
604
		storeManagerMap.put("ajaykumarkansal03@gmail.com",
605
				Arrays.asList("manoj.singh@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
606
		storeManagerMap.put("spurwar73@gmail.com", Arrays.asList("md.anis@smartdukaan.com",
607
				"rajat.gupta@smartdukaan.com", "adeel.yazdani@smartdukaan.com"));
608
		storeManagerMap.put("Shreemobile.ind@gmail.com", Arrays.asList("md.anis@smartdukaan.com",
609
				"rajat.gupta@smartdukaan.com", "adeel.yazdani@smartdukaan.com"));
610
		storeManagerMap.put("felixenterprises2017@rediffmail.com",
611
				Arrays.asList("", "dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
612
		storeManagerMap.put("nareandergupta@gmail.com",
613
				Arrays.asList("", "dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
614
		storeManagerMap.put("shreebalajielectronic2019@gmail.com",
615
				Arrays.asList("manoj.singh@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
616
		storeManagerMap.put("saranshary@gmail.com",
617
				Arrays.asList("", "dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
618
		storeManagerMap.put("gambhirsmartphone@gmail.com",
619
				Arrays.asList("", "gulshan.kumar@smartdukaan.com", "adeel.yazdani@smartdukaan.com"));
620
		storeManagerMap.put("Priyankaenterprises9910@gmail.com",
621
				Arrays.asList("manoj.singh@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
622
		storeManagerMap.put("pawan.dhimaan@gmail.com",
623
				Arrays.asList("", "dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
624
		storeManagerMap.put("lakshaydhulla62@gmail.com", Arrays.asList("parmod.sharma@smartdukaan.com",
625
				"dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
626
		storeManagerMap.put("parastelecom.stp@gmail.com", Arrays.asList("md.anis@smartdukaan.com",
627
				"rajat.gupta@smartdukaan.com", "adeel.yazdani@smartdukaan.com"));
628
		storeManagerMap.put("talwarmukesh298@gmail.com", Arrays.asList("parmod.sharma@smartdukaan.com",
629
				"dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
630
		storeManagerMap.put("sahilnarang0009@gmail.com",
631
				Arrays.asList("parmod.sharma@smartdukaan.com", "", "mohinder.mutreja@smartdukaan.com"));
632
		storeManagerMap.put("supertelecomjind@gmail.com",
633
				Arrays.asList("", "ankit.bhatia@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
634
		storeManagerMap.put("saketnagpal@gmail.com",
635
				Arrays.asList("", "rajit.alag@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
636
		storeManagerMap.put("DEEPAKGOYAL702.DG@GMAIL.COM",
637
				Arrays.asList("", "ankit.bhatia@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
638
		storeManagerMap.put("sambhav350@gmail.com", Arrays.asList("parmod.sharma@smartdukaan.com",
639
				"dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
640
		storeManagerMap.put("mayankarora98133@gmail.com",
641
				Arrays.asList("", "ankit.bhatia@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
642
		storeManagerMap.put("vijaymobilityandmoew@gmail.com",
643
				Arrays.asList("manoj.singh@smartdukaan.com", "", "adeel.yazdani@smartdukaan.com"));
644
		storeManagerMap.put("amitv70003@gmail.com",
645
				Arrays.asList("", "ankit.bhatia@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
646
		storeManagerMap.put("newagelucknow.123@gmail.com", Arrays.asList("md.anis@smartdukaan.com",
647
				"rajat.gupta@smartdukaan.com", "adeel.yazdani@smartdukaan.com"));
648
		storeManagerMap.put("Newagetechnologygomtinagar@gmail.com", Arrays.asList("md.anis@smartdukaan.com",
649
				"rajat.gupta@smartdukaan.com", "adeel.yazdani@smartdukaan.com"));
650
		storeManagerMap.put("rohitbatra106@gmail.com", Arrays.asList("parmod.sharma@smartdukaan.com",
651
				"dharmender.verma@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
652
		storeManagerMap.put("sonisunil9050873061@gmail.com",
653
				Arrays.asList("", "ankit.bhatia@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
654
		storeManagerMap.put("moderncohsr@gmail.com",
655
				Arrays.asList("", "ankit.bhatia@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
656
		storeManagerMap.put("raghubir.ngh@gmail.com",
657
				Arrays.asList("", "ankit.bhatia@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
658
		storeManagerMap.put("aman007singla@gmail.com",
659
				Arrays.asList("", "rajit.alag@smartdukaan.com", "mohinder.mutreja@smartdukaan.com"));
25366 tejbeer 660
	}
25458 tejbeer 661
 
662
	@RequestMapping(value = "/user/refferal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
663
	@ApiImplicitParams({
664
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
665
	public ResponseEntity<?> RefferalUser(HttpServletRequest request,
666
			@RequestBody CreateRefferalRequest createRefferalRequest) throws Exception {
667
		Refferal refferal = new Refferal();
668
		refferal.setFirstName(createRefferalRequest.getFirstName());
669
		refferal.setLastName(createRefferalRequest.getLastName());
670
		refferal.setMobile(createRefferalRequest.getMobile());
671
		refferal.setState(createRefferalRequest.getState());
672
		refferal.setCity(createRefferalRequest.getCity());
673
		refferal.setCreatedTimestamp(LocalDateTime.now());
674
		refferal.setUpdatedTimestamp(LocalDateTime.now());
675
		refferal.setStatus("pending");
676
		if (createRefferalRequest.isFofoAssociate()) {
677
			AuthUser authUser = authRepository.selectByGmailId(createRefferalRequest.getReffereeEmail());
25483 tejbeer 678
			if (authUser == null) {
25458 tejbeer 679
				Promoter promoter = promoterRepository.selectByEmailId(createRefferalRequest.getReffereeEmail());
680
				refferal.setRefereeName(promoter.getName());
25483 tejbeer 681
				refferal.setRefereeEmail(promoter.getEmail());
25458 tejbeer 682
				refferal.setRefereeMobile(promoter.getMobile());
683
			} else {
684
				refferal.setRefereeName(authUser.getFirstName());
25483 tejbeer 685
				refferal.setRefereeEmail(authUser.getGmailId());
25458 tejbeer 686
				refferal.setRefereeMobile(authUser.getMobileNumber());
687
			}
688
		} else {
689
			User user = userRepository.selectByEmailId(createRefferalRequest.getReffereeEmail());
690
			refferal.setRefereeName(user.getFirstName());
25483 tejbeer 691
			refferal.setRefereeEmail(user.getEmailId());
25458 tejbeer 692
			refferal.setRefereeMobile(user.getMobileNumber());
693
		}
694
 
695
		refferalRepository.persist(refferal);
696
		return responseSender.ok(true);
697
	}
21248 ashik.ali 698
}