Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5432 amar.kumar 1
package in.shop2020.user.handler;
2
 
3
import java.util.ArrayList;
4
import java.util.Date;
5
import java.util.List;
6
 
7
import org.apache.commons.logging.Log;
8
import org.apache.commons.logging.LogFactory;
9
import org.apache.thrift.TException;
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.stereotype.Service;
12
 
13
import in.shop2020.model.v1.user.Address;
14
import in.shop2020.model.v1.user.UserCommunication;
15
import in.shop2020.user.persistence.AddressMapper;
16
import in.shop2020.user.util.Converter;
17
 
18
@Service
19
public class AddressHandler {
20
 
21
	@Autowired
22
	private AddressMapper addressMapper;
23
 
24
	private static final Log log = LogFactory.getLog(AddressHandler.class);
25
 
26
	public long addAddressForUser(in.shop2020.user.domain.Address dbAddress) 
27
		throws TException{
28
			dbAddress.setEnabled(true);
29
			if(dbAddress.getAdded_on()==null) {
30
				dbAddress.setAdded_on(new Date());
31
			}
32
			addressMapper.addAddressForUser(dbAddress);
33
			return dbAddress.getId();
34
	}
35
 
36
	public in.shop2020.user.domain.Address getAddress(long addressId) 
37
		throws TException{
38
			in.shop2020.user.domain.Address address = addressMapper.getAddress(addressId);
39
			if(address!=null) {
40
				return address;
41
			}
42
			log.error("No address found for id : "+addressId);
43
			return null;
44
	}
45
 
46
	public void removeAddressForUser(long addressId) throws TException{
47
			addressMapper.disableAddress(addressId);
48
	}
49
 
50
	public String getPincodeForAddress(long id) throws TException{
51
			return addressMapper.getPincodeForAddress(id);
52
	}
53
 
54
	public List<Address> getAllAddressesForUser(long userId) throws TException{
55
			List<Address> tAddresses = new ArrayList<Address>();
56
			List<in.shop2020.user.domain.Address> addresses = 
57
				new ArrayList<in.shop2020.user.domain.Address>();
58
 
59
			addresses = addressMapper.getAllAddressesForUser(userId);
60
 
61
			for(in.shop2020.user.domain.Address address : addresses) {
62
				tAddresses.add(Converter.toThriftAddress(address));
63
			}
64
			return tAddresses;
65
	}
66
 
67
}