| 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());
|
|
|
40 |
Customer customer = customerRepository.selectByMobileNumber(mobileNumber);
|
|
|
41 |
CustomCustomer customCustomer = new CustomCustomer();
|
|
|
42 |
customCustomer.setEmailId(customer.getEmailId());
|
|
|
43 |
customCustomer.setFirstName(customer.getFirstName());
|
|
|
44 |
customCustomer.setLastName(customer.getLastName());
|
|
|
45 |
customCustomer.setMobileNumber(customer.getMobileNumber());
|
|
|
46 |
customCustomer.setCustomerAddressId(customer.getId());
|
|
|
47 |
if(!customer.getCustomerAddress().isEmpty()){
|
|
|
48 |
CustomerAddress customerAddress = customer.getCustomerAddress().get(0);
|
|
|
49 |
CustomAddress customAddress = new CustomAddress();
|
|
|
50 |
customAddress.setCity(customerAddress.getCity());
|
|
|
51 |
customAddress.setCountry(customerAddress.getCountry());
|
|
|
52 |
customAddress.setLandmark(customerAddress.getLandmark());
|
|
|
53 |
customAddress.setLine1(customerAddress.getLine1());
|
|
|
54 |
customAddress.setLine2(customerAddress.getLine2());
|
|
|
55 |
customAddress.setName(customerAddress.getName());
|
|
|
56 |
customAddress.setPhoneNumber(customerAddress.getPhoneNumber());
|
|
|
57 |
customAddress.setPinCode(customerAddress.getPinCode());
|
|
|
58 |
customAddress.setState(customerAddress.getState());
|
|
|
59 |
customAddress.setId(customerAddress.getId());
|
|
|
60 |
customCustomer.setAddress(customAddress);
|
| 22354 |
ashik.ali |
61 |
}
|
| 22927 |
ashik.ali |
62 |
return responseSender.ok(customCustomer);
|
| 22354 |
ashik.ali |
63 |
}
|
|
|
64 |
}
|