Subversion Repositories SmartDukaan

Rev

Rev 22860 | Go to most recent revision | Details | 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.CustomerAddressRepository;
23
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
24
 
25
@Controller
26
@Transactional
27
public class CustomerController {
28
 
29
	private static final Logger LOGGER = LoggerFactory.getLogger(CustomerController.class);
30
 
31
	@Autowired
32
	ResponseSender<?> responseSender;
33
 
34
	@Autowired
35
	CustomerRepository customerRepository;
36
 
37
	@Autowired
38
	CustomerAddressRepository customerAddressRepository;
39
 
40
	@RequestMapping(value = "/customer/mobileNumber", method = RequestMethod.GET)
41
	public ResponseEntity<?> getCustomerByMobileNumber(HttpServletRequest request, @RequestParam (name = ProfitMandiConstants.MOBILE_NUMBER) String mobileNumber){
42
		try{
43
			Customer customer = customerRepository.selectByMobileNumber(mobileNumber);
44
			CustomCustomer customCustomer = new CustomCustomer();
45
			customCustomer.setEmailId(customer.getEmailId());
46
			customCustomer.setFirstName(customer.getFirstName());
47
			customCustomer.setLastName(customer.getLastName());
48
			customCustomer.setMobileNumber(customer.getMobileNumber());
49
			customCustomer.setCustomerAddressId(customer.getId());
50
			if(!customer.getCustomerAddress().isEmpty()){
51
				CustomerAddress customerAddress = customer.getCustomerAddress().get(0);
52
				CustomAddress customAddress = new CustomAddress();
53
				customAddress.setCity(customAddress.getCity());
54
				customAddress.setCountry(customerAddress.getCountry());
55
				customAddress.setLandmark(customerAddress.getLandmark());
56
				customAddress.setLine1(customerAddress.getLine1());
57
				customAddress.setLine2(customerAddress.getLine2());
58
				customAddress.setName(customerAddress.getName());
59
				customAddress.setPhoneNumber(customerAddress.getPhoneNumber());
60
				customAddress.setPinCode(customerAddress.getPinCode());
61
				customAddress.setState(customAddress.getState());
62
				customCustomer.setAddress(customAddress);
63
			}
64
			return responseSender.ok(customCustomer);
65
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
66
			LOGGER.info("Customer not found with mobileNumber [{}]", mobileNumber);
67
			return responseSender.badRequest(profitMandiBusinessException);
68
		}
69
	}
70
}