Subversion Repositories SmartDukaan

Rev

Rev 23584 | Rev 25170 | 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 javax.servlet.http.HttpServletRequest;


import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
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
@Transactional
public class CustomerController {
        
        private static final Logger LOGGER = LogManager.getLogger(CustomerController.class);
        
        @Autowired
        private ResponseSender<?> responseSender;
        
        @Autowired
        private 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());
                try {
                        Customer customer= customerRepository.selectByMobileNumber(mobileNumber);
                        CustomCustomer customCustomer = new CustomCustomer();
                        customCustomer.setEmailId(customer.getEmailId());
                        customCustomer.setFirstName(customer.getFirstName());
                        customCustomer.setLastName(customer.getLastName());
                        customCustomer.setMobileNumber(customer.getMobileNumber());
                        customCustomer.setCustomerAddressId(customer.getId());
                        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);
                } catch(Exception e) {
                        return responseSender.ok("");
                }
        }
}