Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
22354 ashik.ali 1
package com.spice.profitmandi.web.controller;
2
 
25170 amit.gupta 3
import java.util.List;
4
 
22354 ashik.ali 5
import javax.servlet.http.HttpServletRequest;
6
 
25170 amit.gupta 7
import org.apache.logging.log4j.LogManager;
23568 govind 8
import org.apache.logging.log4j.Logger;
22354 ashik.ali 9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.http.ResponseEntity;
11
import org.springframework.stereotype.Controller;
12
import org.springframework.transaction.annotation.Transactional;
13
import org.springframework.web.bind.annotation.RequestMapping;
14
import org.springframework.web.bind.annotation.RequestMethod;
15
import org.springframework.web.bind.annotation.RequestParam;
16
 
17
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
18
import com.spice.profitmandi.common.model.CustomAddress;
19
import com.spice.profitmandi.common.model.CustomCustomer;
20
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21
import com.spice.profitmandi.common.web.util.ResponseSender;
22
import com.spice.profitmandi.dao.entity.fofo.Customer;
23
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
24
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
25
 
26
@Controller
27
@Transactional
28
public class CustomerController {
25170 amit.gupta 29
 
23568 govind 30
	private static final Logger LOGGER = LogManager.getLogger(CustomerController.class);
25170 amit.gupta 31
 
22354 ashik.ali 32
	@Autowired
22927 ashik.ali 33
	private ResponseSender<?> responseSender;
25170 amit.gupta 34
 
22354 ashik.ali 35
	@Autowired
22927 ashik.ali 36
	private CustomerRepository customerRepository;
25170 amit.gupta 37
 
22354 ashik.ali 38
	@RequestMapping(value = "/customer/mobileNumber", method = RequestMethod.GET)
25170 amit.gupta 39
	public ResponseEntity<?> getCustomerByMobileNumber(HttpServletRequest request,
40
			@RequestParam(name = ProfitMandiConstants.MOBILE_NUMBER) String mobileNumber)
41
			throws ProfitMandiBusinessException {
22927 ashik.ali 42
		LOGGER.info("Request Received at url {}", request.getRequestURI());
25170 amit.gupta 43
		List<Customer> customers = customerRepository.selectAllByMobileNumber(mobileNumber);
44
		if (customers.size() > 0) {
45
			Customer customer = customers.get(0);
24087 amit.gupta 46
			CustomCustomer customCustomer = new CustomCustomer();
47
			customCustomer.setEmailId(customer.getEmailId());
48
			customCustomer.setFirstName(customer.getFirstName());
49
			customCustomer.setLastName(customer.getLastName());
50
			customCustomer.setMobileNumber(customer.getMobileNumber());
25170 amit.gupta 51
			if (!customer.getCustomerAddress().isEmpty()) {
24087 amit.gupta 52
				CustomerAddress customerAddress = customer.getCustomerAddress().get(0);
53
				CustomAddress customAddress = new CustomAddress();
54
				customAddress.setCity(customerAddress.getCity());
55
				customAddress.setCountry(customerAddress.getCountry());
56
				customAddress.setLandmark(customerAddress.getLandmark());
57
				customAddress.setLine1(customerAddress.getLine1());
58
				customAddress.setLine2(customerAddress.getLine2());
59
				customAddress.setName(customerAddress.getName());
60
				customAddress.setPhoneNumber(customerAddress.getPhoneNumber());
61
				customAddress.setPinCode(customerAddress.getPinCode());
62
				customAddress.setState(customerAddress.getState());
63
				customAddress.setId(customerAddress.getId());
64
				customCustomer.setAddress(customAddress);
65
			}
66
			return responseSender.ok(customCustomer);
25170 amit.gupta 67
		} else {
24087 amit.gupta 68
			return responseSender.ok("");
22354 ashik.ali 69
		}
70
	}
71
}