| Line 23... |
Line 23... |
| 23 |
import org.springframework.web.bind.annotation.RequestParam;
|
23 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 24 |
|
24 |
|
| 25 |
import com.google.gson.Gson;
|
25 |
import com.google.gson.Gson;
|
| 26 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
26 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 27 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
27 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 28 |
import com.spice.profitmandi.dao.entity.dtr.UserAccounts;
|
28 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 29 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
29 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
| 30 |
import com.spice.profitmandi.dao.model.ProductPojo;
|
30 |
import com.spice.profitmandi.dao.model.ProductPojo;
|
| 31 |
import com.spice.profitmandi.dao.model.UserCart;
|
31 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 32 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
32 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 33 |
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
|
33 |
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
|
| Line 67... |
Line 67... |
| 67 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
67 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
| 68 |
required = true, dataType = "string", paramType = "header")
|
68 |
required = true, dataType = "string", paramType = "header")
|
| 69 |
})
|
69 |
})
|
| 70 |
@ApiOperation(value = "Add items to cart")
|
70 |
@ApiOperation(value = "Add items to cart")
|
| 71 |
public ResponseEntity<?> validateCart(HttpServletRequest request,@RequestBody AddCartRequest cartRequest, @RequestParam(value="pincode", defaultValue="110001") String pincode) throws Throwable{
|
71 |
public ResponseEntity<?> validateCart(HttpServletRequest request,@RequestBody AddCartRequest cartRequest, @RequestParam(value="pincode", defaultValue="110001") String pincode) throws Throwable{
|
| 72 |
UserAccounts userAccount = null;
|
72 |
UserAccount userAccount = null;
|
| 73 |
ValidateCartResponse vc = null;
|
73 |
ValidateCartResponse vc = null;
|
| 74 |
int userId = (int)request.getAttribute("userId");
|
74 |
int userId = (int)request.getAttribute("userId");
|
| 75 |
|
75 |
|
| 76 |
userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.cartId);
|
76 |
userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.cartId);
|
| 77 |
logger.info("UserAccount "+userAccount);
|
77 |
logger.info("UserAccount "+userAccount);
|
| 78 |
|
78 |
|
| 79 |
List<ItemQuantity> itemQuantities = new ArrayList<ItemQuantity>();
|
79 |
List<ItemQuantity> itemQuantities = new ArrayList<ItemQuantity>();
|
| 80 |
CartItems[] cartItems = cartRequest.getCartItems();
|
80 |
CartItems[] cartItems = cartRequest.getCartItems();
|
| 81 |
List<Integer> itemsList = new ArrayList<Integer>();
|
81 |
List<Integer> itemsList = new ArrayList<Integer>();
|
| Line 85... |
Line 85... |
| 85 |
itemQuantities.add(iq);
|
85 |
itemQuantities.add(iq);
|
| 86 |
}
|
86 |
}
|
| 87 |
Client userClient = null;
|
87 |
Client userClient = null;
|
| 88 |
try {
|
88 |
try {
|
| 89 |
userClient = new UserClient().getClient();
|
89 |
userClient = new UserClient().getClient();
|
| 90 |
userClient.addItemsToCart(Integer.valueOf(userAccount.getAccount_key()), itemQuantities, null);
|
90 |
userClient.addItemsToCart(Integer.valueOf(userAccount.getAccountKey()), itemQuantities, null);
|
| 91 |
} catch (Exception e) {
|
91 |
} catch (Exception e) {
|
| 92 |
vc = new ValidateCartResponse(null, "Error","Problem occurred while updating cart");
|
92 |
vc = new ValidateCartResponse(null, "Error","Problem occurred while updating cart");
|
| 93 |
return responseSender.internalServerError(vc);
|
93 |
return responseSender.internalServerError(vc);
|
| 94 |
}
|
94 |
}
|
| 95 |
String cartString=null;
|
95 |
String cartString=null;
|
| 96 |
//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
|
| 97 |
int source = -1;
|
97 |
int source = -1;
|
| 98 |
cartString = userClient.validateCartNew(Integer.valueOf(userAccount.getAccount_key()), pincode, source);
|
98 |
cartString = userClient.validateCartNew(Integer.valueOf(userAccount.getAccountKey()), pincode, source);
|
| 99 |
JSONObject cartObj = new JSONObject(cartString);
|
99 |
JSONObject cartObj = new JSONObject(cartString);
|
| 100 |
JSONArray arr = cartObj.getJSONArray("cartItems");
|
100 |
JSONArray arr = cartObj.getJSONArray("cartItems");
|
| 101 |
int maxEstimate=-2;
|
101 |
int maxEstimate=-2;
|
| 102 |
boolean allSame=true;
|
102 |
boolean allSame=true;
|
| 103 |
int removedCount = 0;
|
103 |
int removedCount = 0;
|