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