| 21378 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
| 24422 |
amit.gupta |
4 |
import java.util.HashMap;
|
| 21378 |
kshitij.so |
5 |
import java.util.List;
|
| 24422 |
amit.gupta |
6 |
import java.util.Map;
|
| 21378 |
kshitij.so |
7 |
|
|
|
8 |
import javax.servlet.http.HttpServletRequest;
|
|
|
9 |
|
| 23959 |
amit.gupta |
10 |
import org.apache.logging.log4j.LogManager;
|
|
|
11 |
import org.apache.logging.log4j.Logger;
|
| 21378 |
kshitij.so |
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
13 |
import org.springframework.http.MediaType;
|
|
|
14 |
import org.springframework.http.ResponseEntity;
|
|
|
15 |
import org.springframework.stereotype.Controller;
|
| 21707 |
amit.gupta |
16 |
import org.springframework.transaction.annotation.Transactional;
|
| 21378 |
kshitij.so |
17 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
18 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
19 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21393 |
amit.gupta |
20 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21378 |
kshitij.so |
21 |
|
|
|
22 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21741 |
ashik.ali |
23 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 28653 |
amit.gupta |
24 |
import com.spice.profitmandi.dao.cart.CartService;
|
| 23273 |
ashik.ali |
25 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 21735 |
ashik.ali |
26 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
| 26607 |
amit.gupta |
27 |
import com.spice.profitmandi.dao.model.AddCartRequest;
|
|
|
28 |
import com.spice.profitmandi.dao.model.CartItem;
|
| 28653 |
amit.gupta |
29 |
import com.spice.profitmandi.dao.model.CartItemResponseModel;
|
| 26607 |
amit.gupta |
30 |
import com.spice.profitmandi.dao.model.CartResponse;
|
| 21378 |
kshitij.so |
31 |
import com.spice.profitmandi.dao.model.ProductPojo;
|
| 21738 |
amit.gupta |
32 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 23360 |
amit.gupta |
33 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 21735 |
ashik.ali |
34 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 21643 |
ashik.ali |
35 |
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
|
| 25962 |
amit.gupta |
36 |
import com.spice.profitmandi.service.inventory.ItemBucketService;
|
| 21378 |
kshitij.so |
37 |
import com.spice.profitmandi.thrift.clients.UserClient;
|
|
|
38 |
import com.spice.profitmandi.web.res.ValidateCartResponse;
|
|
|
39 |
|
|
|
40 |
import in.shop2020.model.v1.user.ItemQuantity;
|
| 21393 |
amit.gupta |
41 |
import in.shop2020.model.v1.user.UserContextService;
|
| 21378 |
kshitij.so |
42 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
43 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
44 |
import io.swagger.annotations.ApiOperation;
|
|
|
45 |
|
|
|
46 |
@Controller
|
| 24199 |
amit.gupta |
47 |
@Transactional(rollbackFor = Throwable.class)
|
| 21378 |
kshitij.so |
48 |
public class CartController {
|
|
|
49 |
|
| 24199 |
amit.gupta |
50 |
private static final Logger logger = LogManager.getLogger(CartController.class);
|
|
|
51 |
|
| 21440 |
ashik.ali |
52 |
@Autowired
|
| 22931 |
ashik.ali |
53 |
private ResponseSender<?> responseSender;
|
| 21378 |
kshitij.so |
54 |
|
|
|
55 |
@Autowired
|
| 22931 |
ashik.ali |
56 |
private UserAccountRepository userAccountRepository;
|
| 24199 |
amit.gupta |
57 |
|
| 22173 |
amit.gupta |
58 |
@Autowired
|
| 25962 |
amit.gupta |
59 |
private ItemBucketService itemBucketService;
|
|
|
60 |
|
|
|
61 |
@Autowired
|
| 28653 |
amit.gupta |
62 |
CartService cartService;
|
|
|
63 |
|
|
|
64 |
@Autowired
|
| 22931 |
ashik.ali |
65 |
private ContentPojoPopulator contentPojoPopulator;
|
| 24199 |
amit.gupta |
66 |
|
| 23360 |
amit.gupta |
67 |
@Autowired
|
|
|
68 |
private ItemRepository itemRepository;
|
| 21378 |
kshitij.so |
69 |
|
| 24422 |
amit.gupta |
70 |
public static final Map<String, Integer> MIN_BRAND_QTY_LIMIT = new HashMap<>();
|
|
|
71 |
|
|
|
72 |
static {
|
| 25962 |
amit.gupta |
73 |
// MIN_BRAND_QTY_LIMIT.put("Realme", 10);
|
| 24464 |
amit.gupta |
74 |
MIN_BRAND_QTY_LIMIT.put("Reliance", 5);
|
| 24422 |
amit.gupta |
75 |
}
|
|
|
76 |
|
| 25962 |
amit.gupta |
77 |
@RequestMapping(value = ProfitMandiConstants.URL_CART, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
78 |
@ApiImplicitParams({
|
|
|
79 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
80 |
@ApiOperation(value = "Add items to cart")
|
|
|
81 |
public ResponseEntity<?> validateCart(HttpServletRequest request,
|
|
|
82 |
@RequestParam(value = "pincode", defaultValue = "110001") String pincode, @RequestParam int bucketId)
|
|
|
83 |
throws Throwable {
|
|
|
84 |
|
|
|
85 |
AddCartRequest cartRequest = new AddCartRequest();
|
| 26607 |
amit.gupta |
86 |
List<CartItem> ci = new ArrayList<>();
|
| 25962 |
amit.gupta |
87 |
itemBucketService.getBucketDetails(bucketId).stream().forEach(x -> {
|
| 28653 |
amit.gupta |
88 |
ci.add(new CartItem(x.getQuantity(), x.getItemId()));
|
| 25962 |
amit.gupta |
89 |
});
|
| 26607 |
amit.gupta |
90 |
cartRequest.setCartItems(ci);
|
| 25962 |
amit.gupta |
91 |
return this.validateCart(request, cartRequest, "110001");
|
|
|
92 |
|
|
|
93 |
}
|
|
|
94 |
|
| 24199 |
amit.gupta |
95 |
@RequestMapping(value = ProfitMandiConstants.URL_CART, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21378 |
kshitij.so |
96 |
@ApiImplicitParams({
|
| 24199 |
amit.gupta |
97 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 21378 |
kshitij.so |
98 |
@ApiOperation(value = "Add items to cart")
|
| 24199 |
amit.gupta |
99 |
public ResponseEntity<?> validateCart(HttpServletRequest request, @RequestBody AddCartRequest cartRequest,
|
|
|
100 |
@RequestParam(value = "pincode", defaultValue = "110001") String pincode) throws Throwable {
|
| 23273 |
ashik.ali |
101 |
UserAccount userAccount = null;
|
| 21378 |
kshitij.so |
102 |
ValidateCartResponse vc = null;
|
| 24199 |
amit.gupta |
103 |
int userId = (int) request.getAttribute("userId");
|
|
|
104 |
|
| 28653 |
amit.gupta |
105 |
int cartId = userAccountRepository.selectByUserIdType(userId, AccountType.cartId).getAccountKey();
|
| 26607 |
amit.gupta |
106 |
List<CartItem> cartItems = cartRequest.getCartItems();
|
| 28653 |
amit.gupta |
107 |
cartService.addItemsToCart(cartId, cartItems);
|
|
|
108 |
CartResponse cartValidationResponse = cartService.getCartValidation(cartId);
|
|
|
109 |
for (CartItemResponseModel cartItem : cartValidationResponse.getCartItems()) {
|
|
|
110 |
ProductPojo pp = contentPojoPopulator.getShortContent(cartItem.getCatalogItemId());
|
|
|
111 |
if(pp!=null) {
|
|
|
112 |
cartItem.setImageUrl(pp.getImageUrl());
|
|
|
113 |
cartItem.setTitle(pp.getTitle());
|
| 24153 |
amit.gupta |
114 |
}
|
|
|
115 |
}
|
| 28653 |
amit.gupta |
116 |
vc = new ValidateCartResponse(cartValidationResponse, "Success", "Items added to cart successfully");
|
| 23021 |
ashik.ali |
117 |
return responseSender.ok(vc);
|
| 21378 |
kshitij.so |
118 |
}
|
| 21393 |
amit.gupta |
119 |
|
| 24199 |
amit.gupta |
120 |
@RequestMapping(value = ProfitMandiConstants.URL_CART_CHANGE_ADDRESS, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21393 |
amit.gupta |
121 |
@ApiImplicitParams({
|
| 24199 |
amit.gupta |
122 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
123 |
|
| 21393 |
amit.gupta |
124 |
@ApiOperation(value = "Change address")
|
| 24199 |
amit.gupta |
125 |
public ResponseEntity<?> changeAddress(HttpServletRequest request,
|
|
|
126 |
@RequestParam(value = "addressId") long addressId) throws Throwable {
|
|
|
127 |
UserCart uc = userAccountRepository.getUserCart((int) request.getAttribute("userId"));
|
| 28653 |
amit.gupta |
128 |
cartService.addAddressToCart(uc.getCartId(), addressId);
|
| 24199 |
amit.gupta |
129 |
return responseSender.ok("Address Changed successfully");
|
|
|
130 |
}
|
| 21378 |
kshitij.so |
131 |
}
|