Subversion Repositories SmartDukaan

Rev

Rev 22860 | Rev 23568 | 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.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 = LoggerFactory.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());
                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);
        }
}