Subversion Repositories SmartDukaan

Rev

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

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