Subversion Repositories SmartDukaan

Rev

Rev 22931 | Rev 23273 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 22931 Rev 23021
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.time.LocalDateTime;
-
 
4
import java.util.ArrayList;
3
import java.util.ArrayList;
5
import java.util.Arrays;
4
import java.util.Arrays;
6
import java.util.List;
5
import java.util.List;
7
 
6
 
8
import javax.servlet.http.HttpServletRequest;
7
import javax.servlet.http.HttpServletRequest;
Line 12... Line 11...
12
import org.json.JSONException;
11
import org.json.JSONException;
13
import org.json.JSONObject;
12
import org.json.JSONObject;
14
import org.slf4j.Logger;
13
import org.slf4j.Logger;
15
import org.slf4j.LoggerFactory;
14
import org.slf4j.LoggerFactory;
16
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.http.HttpStatus;
-
 
18
import org.springframework.http.MediaType;
16
import org.springframework.http.MediaType;
19
import org.springframework.http.ResponseEntity;
17
import org.springframework.http.ResponseEntity;
20
import org.springframework.stereotype.Controller;
18
import org.springframework.stereotype.Controller;
21
import org.springframework.transaction.annotation.Transactional;
19
import org.springframework.transaction.annotation.Transactional;
22
import org.springframework.web.bind.annotation.RequestBody;
20
import org.springframework.web.bind.annotation.RequestBody;
Line 24... Line 22...
24
import org.springframework.web.bind.annotation.RequestMethod;
22
import org.springframework.web.bind.annotation.RequestMethod;
25
import org.springframework.web.bind.annotation.RequestParam;
23
import org.springframework.web.bind.annotation.RequestParam;
26
 
24
 
27
import com.google.gson.Gson;
25
import com.google.gson.Gson;
28
import com.spice.profitmandi.common.model.ProfitMandiConstants;
26
import com.spice.profitmandi.common.model.ProfitMandiConstants;
29
import com.spice.profitmandi.common.model.ProfitMandiResponse;
-
 
30
import com.spice.profitmandi.common.model.ResponseStatus;
-
 
31
import com.spice.profitmandi.common.web.util.ResponseSender;
27
import com.spice.profitmandi.common.web.util.ResponseSender;
32
import com.spice.profitmandi.dao.entity.dtr.UserAccounts;
28
import com.spice.profitmandi.dao.entity.dtr.UserAccounts;
33
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
29
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
34
import com.spice.profitmandi.dao.model.ProductPojo;
30
import com.spice.profitmandi.dao.model.ProductPojo;
35
import com.spice.profitmandi.dao.model.UserCart;
31
import com.spice.profitmandi.dao.model.UserCart;
36
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
32
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
37
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
-
 
38
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
33
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
39
import com.spice.profitmandi.dao.util.LogisticsService;
34
import com.spice.profitmandi.dao.util.LogisticsService;
40
import com.spice.profitmandi.thrift.clients.UserClient;
35
import com.spice.profitmandi.thrift.clients.UserClient;
41
import com.spice.profitmandi.web.req.AddCartRequest;
36
import com.spice.profitmandi.web.req.AddCartRequest;
42
import com.spice.profitmandi.web.req.CartItems;
37
import com.spice.profitmandi.web.req.CartItems;
Line 93... Line 88...
93
		try {
88
		try {
94
			userClient = new UserClient().getClient();
89
			userClient = new UserClient().getClient();
95
			userClient.addItemsToCart(Integer.valueOf(userAccount.getAccount_key()), itemQuantities, null);
90
			userClient.addItemsToCart(Integer.valueOf(userAccount.getAccount_key()), itemQuantities, null);
96
		} catch (Exception e) {
91
		} catch (Exception e) {
97
			vc = new ValidateCartResponse(null, "Error","Problem occurred while updating cart");
92
			vc = new ValidateCartResponse(null, "Error","Problem occurred while updating cart");
98
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, vc);
-
 
99
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
93
			return responseSender.internalServerError(vc);
100
		}
94
		}
101
		String cartString=null;
95
		String cartString=null;
102
		//Use source id temporarily for purpose of tag id as it is just one lets hardcode the tag id
96
		//Use source id temporarily for purpose of tag id as it is just one lets hardcode the tag id
103
		int source = -1;
97
		int source = -1;
104
		cartString = userClient.validateCartNew(Integer.valueOf(userAccount.getAccount_key()), pincode, source);
98
		cartString = userClient.validateCartNew(Integer.valueOf(userAccount.getAccount_key()), pincode, source);
Line 214... Line 208...
214
				cartObj.put("estimateString", LogisticsService.getDeliveryDateString(maxEstimate,DeliveryType.COD));
208
				cartObj.put("estimateString", LogisticsService.getDeliveryDateString(maxEstimate,DeliveryType.COD));
215
			} catch (NumberFormatException | JSONException | TException e) {
209
			} catch (NumberFormatException | JSONException | TException e) {
216
				// TODO Auto-generated catch block
210
				// TODO Auto-generated catch block
217
				e.printStackTrace();
211
				e.printStackTrace();
218
				vc = new ValidateCartResponse(null, "Error","Problem occurred while getting delivery estimates");
212
				vc = new ValidateCartResponse(null, "Error","Problem occurred while getting delivery estimates");
219
				final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , 
-
 
220
						HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, vc);
-
 
221
				return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
213
				return responseSender.internalServerError(vc);
222
			}
214
			}
223
			
215
			
224
		}
216
		}
225
		cartObj.put("maxEstimate", maxEstimate);
217
		cartObj.put("maxEstimate", maxEstimate);
226
		CartResponse cartResponse = new Gson().fromJson(cartObj.toString(), CartResponse.class);
218
		CartResponse cartResponse = new Gson().fromJson(cartObj.toString(), CartResponse.class);
227
		vc = new ValidateCartResponse(cartResponse, "Success","Items added to cart successfully");
219
		vc = new ValidateCartResponse(cartResponse, "Success","Items added to cart successfully");
228
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, vc);
-
 
229
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
220
		return responseSender.ok(vc);
230
	}
221
	}
231
 
222
 
232
	@RequestMapping(value = ProfitMandiConstants.URL_CART_CHANGE_ADDRESS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
223
	@RequestMapping(value = ProfitMandiConstants.URL_CART_CHANGE_ADDRESS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
233
	@ApiImplicitParams({
224
	@ApiImplicitParams({
234
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
225
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",