Blame | Last modification | View Log | RSS feed
package in.shop2020.user.handler;import java.util.ArrayList;import java.util.Date;import java.util.List;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.thrift.TException;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import in.shop2020.model.v1.user.Address;import in.shop2020.model.v1.user.UserCommunication;import in.shop2020.user.persistence.AddressMapper;import in.shop2020.user.util.Converter;@Servicepublic class AddressHandler {@Autowiredprivate AddressMapper addressMapper;private static final Log log = LogFactory.getLog(AddressHandler.class);public long addAddressForUser(in.shop2020.user.domain.Address dbAddress)throws TException{dbAddress.setEnabled(true);if(dbAddress.getAdded_on()==null) {dbAddress.setAdded_on(new Date());}addressMapper.addAddressForUser(dbAddress);return dbAddress.getId();}public in.shop2020.user.domain.Address getAddress(long addressId)throws TException{in.shop2020.user.domain.Address address = addressMapper.getAddress(addressId);if(address!=null) {return address;}log.error("No address found for id : "+addressId);return null;}public void removeAddressForUser(long addressId) throws TException{addressMapper.disableAddress(addressId);}public String getPincodeForAddress(long id) throws TException{return addressMapper.getPincodeForAddress(id);}public List<Address> getAllAddressesForUser(long userId) throws TException{List<Address> tAddresses = new ArrayList<Address>();List<in.shop2020.user.domain.Address> addresses =new ArrayList<in.shop2020.user.domain.Address>();addresses = addressMapper.getAllAddressesForUser(userId);for(in.shop2020.user.domain.Address address : addresses) {tAddresses.add(Converter.toThriftAddress(address));}return tAddresses;}}