Rev 24087 | Rev 26806 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.controller;import java.util.List;import javax.servlet.http.HttpServletRequest;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.http.ResponseEntity;import org.springframework.stereotype.Controller;import org.springframework.transaction.annotation.Transactional;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.common.model.CustomAddress;import com.spice.profitmandi.common.model.CustomCustomer;import com.spice.profitmandi.common.model.ProfitMandiConstants;import com.spice.profitmandi.common.web.util.ResponseSender;import com.spice.profitmandi.dao.entity.fofo.Customer;import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;@Controller@Transactionalpublic class CustomerController {private static final Logger LOGGER = LogManager.getLogger(CustomerController.class);@Autowiredprivate ResponseSender<?> responseSender;@Autowiredprivate CustomerRepository customerRepository;@RequestMapping(value = "/customer/mobileNumber", method = RequestMethod.GET)public ResponseEntity<?> getCustomerByMobileNumber(HttpServletRequest request,@RequestParam(name = ProfitMandiConstants.MOBILE_NUMBER) String mobileNumber)throws ProfitMandiBusinessException {LOGGER.info("Request Received at url {}", request.getRequestURI());List<Customer> customers = customerRepository.selectAllByMobileNumber(mobileNumber);if (customers.size() > 0) {Customer customer = customers.get(0);CustomCustomer customCustomer = new CustomCustomer();customCustomer.setEmailId(customer.getEmailId());customCustomer.setFirstName(customer.getFirstName());customCustomer.setLastName(customer.getLastName());customCustomer.setMobileNumber(customer.getMobileNumber());if (!customer.getCustomerAddress().isEmpty()) {CustomerAddress customerAddress = customer.getCustomerAddress().get(0);CustomAddress customAddress = new CustomAddress();customAddress.setCity(customerAddress.getCity());customAddress.setCountry(customerAddress.getCountry());customAddress.setLandmark(customerAddress.getLandmark());customAddress.setLine1(customerAddress.getLine1());customAddress.setLine2(customerAddress.getLine2());customAddress.setName(customerAddress.getName());customAddress.setPhoneNumber(customerAddress.getPhoneNumber());customAddress.setPinCode(customerAddress.getPinCode());customAddress.setState(customerAddress.getState());customAddress.setId(customerAddress.getId());customCustomer.setAddress(customAddress);}return responseSender.ok(customCustomer);} else {return responseSender.ok("");}}}