Subversion Repositories SmartDukaan

Rev

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