Subversion Repositories SmartDukaan

Rev

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