| 36321 |
vikas |
1 |
package com.spice.profitmandi.web.v2.controller;
|
|
|
2 |
|
| 36376 |
aman |
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 36321 |
vikas |
4 |
import com.spice.profitmandi.common.model.SamsungUpgradeOfferModel;
|
|
|
5 |
import com.spice.profitmandi.common.model.CreateOrderRequest;
|
|
|
6 |
import com.spice.profitmandi.common.model.InsuranceModel;
|
| 36388 |
aman |
7 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 36376 |
aman |
8 |
import com.spice.profitmandi.dao.cart.CartService;
|
|
|
9 |
import com.spice.profitmandi.dao.entity.user.Address;
|
|
|
10 |
import com.spice.profitmandi.dao.model.UserCart;
|
|
|
11 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
12 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 36321 |
vikas |
13 |
import com.spice.profitmandi.web.controller.checkout.OrderController;
|
|
|
14 |
import com.spice.profitmandi.web.v2.response.ApiResponse;
|
|
|
15 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
17 |
import org.springframework.http.ResponseEntity;
|
|
|
18 |
import org.springframework.ui.Model;
|
| 36376 |
aman |
19 |
import org.springframework.transaction.annotation.Transactional;
|
| 36321 |
vikas |
20 |
import org.springframework.web.bind.annotation.*;
|
|
|
21 |
|
|
|
22 |
import javax.servlet.http.HttpServletRequest;
|
|
|
23 |
import javax.servlet.http.HttpServletResponse;
|
| 36391 |
aman |
24 |
import java.time.LocalDate;
|
| 36376 |
aman |
25 |
import java.time.LocalDateTime;
|
| 36321 |
vikas |
26 |
import java.time.YearMonth;
|
|
|
27 |
import java.util.List;
|
|
|
28 |
|
|
|
29 |
@RestController
|
|
|
30 |
@RequestMapping("/v2")
|
| 36376 |
aman |
31 |
@Transactional(rollbackFor = Throwable.class)
|
| 36321 |
vikas |
32 |
public class V2OrderController extends V2BaseController {
|
|
|
33 |
|
|
|
34 |
@Autowired
|
|
|
35 |
private OrderController orderController;
|
|
|
36 |
|
| 36376 |
aman |
37 |
@Autowired
|
|
|
38 |
private UserAccountRepository userAccountRepository;
|
|
|
39 |
|
|
|
40 |
@Autowired
|
|
|
41 |
private AddressRepository addressRepository;
|
|
|
42 |
|
|
|
43 |
@Autowired
|
|
|
44 |
private CartService cartService;
|
|
|
45 |
|
| 36321 |
vikas |
46 |
@RequestMapping(value = "/order/create", method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
47 |
public ResponseEntity<ApiResponse<?>> createOrder(HttpServletRequest request,
|
|
|
48 |
@RequestParam(value = "paymentOption") String paymentOption,
|
|
|
49 |
@RequestParam(value = "walletUsed") double walletUsed,
|
|
|
50 |
@RequestParam(value = "selfPickup", defaultValue = "false") boolean selfPickup,
|
| 36376 |
aman |
51 |
@RequestParam(defaultValue = "0") int freeCreditDays,
|
|
|
52 |
@RequestParam(value = "reservationId", required = false) String reservationId) throws Throwable {
|
|
|
53 |
return wrapResponse(orderController.createOrder(request, paymentOption, walletUsed, selfPickup, freeCreditDays, reservationId));
|
| 36321 |
vikas |
54 |
}
|
|
|
55 |
|
|
|
56 |
// TODO: paymentOptions writes directly to response via void method - skipping v2 wrapper
|
|
|
57 |
// @GetMapping("/paymentOptions")
|
|
|
58 |
|
|
|
59 |
@GetMapping("/order/payStatus")
|
|
|
60 |
public ResponseEntity<ApiResponse<?>> payStatus(HttpServletRequest request,
|
|
|
61 |
@RequestParam(value = "paymentId") long paymentId) throws Throwable {
|
|
|
62 |
return wrapResponse(orderController.payStatus(request, paymentId));
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
@GetMapping("/order/transactionId")
|
|
|
66 |
public ResponseEntity<ApiResponse<?>> getOrdersByTransactionId(HttpServletRequest request,
|
|
|
67 |
@RequestParam(name = "transactionId") int transactionId) throws Throwable {
|
|
|
68 |
return wrapResponse(orderController.getOrdersByTransactionId(request, transactionId));
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
@GetMapping("/order/all")
|
|
|
72 |
public ResponseEntity<ApiResponse<?>> getOrdersByRetailerId(HttpServletRequest request,
|
|
|
73 |
@RequestParam(defaultValue = "0") int offset,
|
|
|
74 |
@RequestParam(defaultValue = "20") int limit) throws Throwable {
|
|
|
75 |
return wrapResponse(orderController.getOrdersByRetailerId(request, offset, limit));
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
@GetMapping("/order/grnPending")
|
|
|
79 |
public ResponseEntity<ApiResponse<?>> grnPending(HttpServletRequest request) throws Throwable {
|
|
|
80 |
return wrapResponse(orderController.grnPending(request));
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
@GetMapping("/order/billed")
|
|
|
84 |
public ResponseEntity<ApiResponse<?>> billedOrders(HttpServletRequest request) throws Throwable {
|
|
|
85 |
return wrapResponse(orderController.billedOrders(request));
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
@GetMapping("/retailerStock")
|
|
|
89 |
public ResponseEntity<ApiResponse<?>> partnerAllStock(HttpServletRequest request) throws Throwable {
|
|
|
90 |
return wrapResponse(orderController.partnerAllStock(request));
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
@GetMapping("/retailerStock/brandwise/{brand}")
|
|
|
94 |
public ResponseEntity<ApiResponse<?>> partnerAllStockBrandwise(HttpServletRequest request,
|
|
|
95 |
@PathVariable String brand) throws Throwable {
|
|
|
96 |
return wrapResponse(orderController.partnerAllStockBrandwise(request, brand));
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
@GetMapping("/order/orderAll/{status}/{yearMonth}")
|
|
|
100 |
public ResponseEntity<ApiResponse<?>> getOrders(HttpServletRequest request,
|
|
|
101 |
@PathVariable OrderStatus status,
|
|
|
102 |
@PathVariable YearMonth yearMonth) throws Throwable {
|
|
|
103 |
return wrapResponse(orderController.getOrders(request, status, yearMonth));
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
@PostMapping("/partnerCancelOrder")
|
|
|
107 |
public ResponseEntity<ApiResponse<?>> partnerCancelOrder(HttpServletRequest request,
|
|
|
108 |
@RequestParam int orderId,
|
|
|
109 |
@RequestParam String reason) throws Throwable {
|
|
|
110 |
return wrapResponse(orderController.partnerCancelOrder(request, orderId, reason));
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
@PostMapping("/order/cancellation")
|
|
|
114 |
public ResponseEntity<ApiResponse<?>> CancellableRequest(HttpServletRequest request,
|
|
|
115 |
@RequestParam(name = "orderId") long orderId,
|
|
|
116 |
@RequestParam(name = "splitOrderQty") long splitOrderQty) throws Throwable {
|
|
|
117 |
return wrapResponse(orderController.CancellableRequest(request, orderId, splitOrderQty));
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
@GetMapping("/order/list")
|
|
|
121 |
public ResponseEntity<ApiResponse<?>> getOrderListByOrderId(HttpServletRequest request,
|
|
|
122 |
@RequestParam(name = "orderId") List<Integer> orderIds) throws Throwable {
|
|
|
123 |
return wrapResponse(orderController.getOrderListByOrderId(request, orderIds));
|
|
|
124 |
}
|
|
|
125 |
|
| 36376 |
aman |
126 |
/**
|
|
|
127 |
* Direct-JPA address creation. Replaces the legacy
|
|
|
128 |
* {@link OrderController#createAddress} path, which went through the
|
|
|
129 |
* Thrift {@code UserClient} — that requires a remote config service
|
|
|
130 |
* (Consul/ZK) not available in every environment and was throwing NPE
|
|
|
131 |
* on {@code ConfigClient.getClient().get(...)}.
|
|
|
132 |
*/
|
| 36321 |
vikas |
133 |
@PostMapping("/address/create")
|
|
|
134 |
public ResponseEntity<ApiResponse<?>> createAddress(HttpServletRequest request,
|
| 36376 |
aman |
135 |
@RequestBody in.shop2020.model.v1.user.Address body)
|
|
|
136 |
throws ProfitMandiBusinessException {
|
|
|
137 |
Object userIdAttr = request.getAttribute("userId");
|
|
|
138 |
if (!(userIdAttr instanceof Integer)) {
|
|
|
139 |
java.util.Map<String, Object> err = new java.util.HashMap<>();
|
|
|
140 |
err.put("responseStatus", "FAILURE");
|
|
|
141 |
err.put("statusCode", 401);
|
|
|
142 |
err.put("statusMessage", "LOGIN_REQUIRED");
|
|
|
143 |
return ResponseEntity.status(401).body(ApiResponse.success(err));
|
|
|
144 |
}
|
|
|
145 |
int userId = (int) userIdAttr;
|
|
|
146 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
147 |
if (uc == null) {
|
|
|
148 |
throw new ProfitMandiBusinessException("userId", userId, "USER_CART_NOT_FOUND");
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
Address entity = new Address();
|
|
|
152 |
entity.setName(body.getName());
|
|
|
153 |
entity.setLine1(body.getLine1());
|
|
|
154 |
entity.setLine2(body.getLine2());
|
|
|
155 |
entity.setLandmark(body.getLandmark());
|
|
|
156 |
entity.setCity(body.getCity());
|
|
|
157 |
entity.setState(body.getState());
|
|
|
158 |
entity.setPinCode(body.getPin());
|
|
|
159 |
entity.setCountry(body.getCountry() == null ? "India" : body.getCountry());
|
|
|
160 |
entity.setPhoneNumber(body.getPhone());
|
|
|
161 |
entity.setEnabled(true);
|
|
|
162 |
// Entity setter has a historical typo ("Retaier") — keep using it so
|
|
|
163 |
// we don't break every other caller. Renaming is out of scope here.
|
|
|
164 |
entity.setRetaierId(uc.getUserId());
|
|
|
165 |
entity.setCreateTimestamp(LocalDateTime.now());
|
|
|
166 |
entity.setUpdateTimestamp(LocalDateTime.now());
|
|
|
167 |
addressRepository.persist(entity);
|
|
|
168 |
|
|
|
169 |
// Bind the new address to the partner's cart so the very next
|
|
|
170 |
// /v2/cart/open call resolves pincode from it.
|
|
|
171 |
cartService.addAddressToCart(uc.getCartId(), entity.getId());
|
|
|
172 |
|
|
|
173 |
return ResponseEntity.ok(ApiResponse.success((long) entity.getId()));
|
| 36321 |
vikas |
174 |
}
|
|
|
175 |
|
|
|
176 |
// TODO: fetchOnlineOrders writes directly to response via void method - skipping v2 wrapper
|
|
|
177 |
// @GetMapping("/online-orders")
|
|
|
178 |
|
|
|
179 |
@GetMapping("/order/notify-orders")
|
|
|
180 |
public ResponseEntity<ApiResponse<?>> getNotifyOrders(HttpServletRequest request,
|
|
|
181 |
HttpServletResponse response,
|
|
|
182 |
@RequestParam(value = "offset") String offset,
|
|
|
183 |
@RequestParam(value = "limit") String limit) throws Throwable {
|
|
|
184 |
return wrapResponse(orderController.getNotifyOrders(request, response, offset, limit));
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
@PostMapping("/order/notify-color-change")
|
|
|
188 |
public ResponseEntity<ApiResponse<?>> NotifyColorChange(HttpServletRequest request,
|
|
|
189 |
HttpServletResponse response,
|
|
|
190 |
@RequestParam(name = "orderId") int orderId,
|
|
|
191 |
@RequestParam(name = "itemId") int itemId) throws Throwable {
|
|
|
192 |
return wrapResponse(orderController.applyColorChange(request, response, orderId, itemId));
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
@PostMapping("/hold-notify-order")
|
|
|
196 |
public ResponseEntity<ApiResponse<?>> NotifyHold(HttpServletRequest request,
|
|
|
197 |
HttpServletResponse response,
|
|
|
198 |
@RequestParam(name = "orderId") int orderId) throws Throwable {
|
|
|
199 |
return wrapResponse(orderController.NotifyHold(request, response, orderId));
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
@PostMapping("/cancelOrder")
|
|
|
203 |
public ResponseEntity<ApiResponse<?>> cancelOrder(HttpServletRequest request,
|
|
|
204 |
@RequestParam int orderId) throws Throwable {
|
|
|
205 |
return wrapResponse(orderController.cancelOrder(request, orderId));
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
@GetMapping("/order/notify-cancel-orders")
|
|
|
209 |
public ResponseEntity<ApiResponse<?>> getNotifyCancelOrders(HttpServletRequest request,
|
|
|
210 |
HttpServletResponse response,
|
|
|
211 |
@RequestParam(value = "offset") String offset,
|
|
|
212 |
@RequestParam(value = "limit") String limit) throws Throwable {
|
|
|
213 |
return wrapResponse(orderController.getNotifyCancelOrders(request, response, offset, limit));
|
|
|
214 |
}
|
|
|
215 |
|
|
|
216 |
@PostMapping("/cancelNotifyOrder")
|
|
|
217 |
public ResponseEntity<ApiResponse<?>> cancelNotifyOrder(HttpServletRequest request,
|
|
|
218 |
@RequestParam int orderId) throws Throwable {
|
|
|
219 |
return wrapResponse(orderController.cancelNotifyOrder(request, orderId));
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
@PostMapping("/raiseBypassRequest")
|
|
|
223 |
public ResponseEntity<ApiResponse<?>> raiseBypassRequest(HttpServletRequest request) throws Throwable {
|
|
|
224 |
return wrapResponse(orderController.raiseBypassRequest(request));
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
@GetMapping("/item")
|
|
|
228 |
public ResponseEntity<ApiResponse<?>> getItem(HttpServletRequest request,
|
|
|
229 |
Model model,
|
|
|
230 |
@RequestParam String query) throws Throwable {
|
|
|
231 |
return wrapResponse(orderController.getItem(request, model, query));
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
@GetMapping("/checkItemAvailability")
|
|
|
235 |
public ResponseEntity<ApiResponse<?>> getItemAvailability(HttpServletRequest request,
|
|
|
236 |
@RequestParam(name = "itemId") int itemId,
|
|
|
237 |
Model model) throws Throwable {
|
|
|
238 |
return wrapResponse(orderController.getItemAvailability(request, itemId, model));
|
|
|
239 |
}
|
|
|
240 |
|
|
|
241 |
@GetMapping("/getItemPricing")
|
|
|
242 |
public ResponseEntity<ApiResponse<?>> getItemPricing(HttpServletRequest request,
|
|
|
243 |
Model model,
|
|
|
244 |
@RequestParam int itemId) throws Throwable {
|
|
|
245 |
return wrapResponse(orderController.getItemPricing(request, model, itemId));
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
@GetMapping("/getFofoPaymentOptions")
|
|
|
249 |
public ResponseEntity<ApiResponse<?>> getPaymentOptions(HttpServletRequest request) throws Throwable {
|
|
|
250 |
return wrapResponse(orderController.getPaymentOptions(request));
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
@PostMapping("/create-order")
|
|
|
254 |
public ResponseEntity<ApiResponse<?>> createFofoOrder(HttpServletRequest request,
|
|
|
255 |
@RequestBody CreateOrderRequest createOrderRequest,
|
|
|
256 |
Model model) throws Throwable {
|
|
|
257 |
return wrapResponse(orderController.createOrder(request, createOrderRequest, model));
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
@GetMapping("/getCustomerOffers")
|
|
|
261 |
public ResponseEntity<ApiResponse<?>> getCustomerOffers(HttpServletRequest request,
|
|
|
262 |
@RequestParam int itemId,
|
|
|
263 |
@RequestParam String imei,
|
|
|
264 |
@RequestParam int orderId) throws Throwable {
|
|
|
265 |
return wrapResponse(orderController.getCustomerOffers(request, itemId, imei, orderId));
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
@PostMapping("/upgradeOffer/createSamsungUpgradeOffer")
|
|
|
269 |
public ResponseEntity<ApiResponse<?>> createSamsungUpgradeOffer(HttpServletRequest request,
|
|
|
270 |
@RequestBody SamsungUpgradeOfferModel suom) throws Throwable {
|
|
|
271 |
return wrapResponse(orderController.createSamsungUpgradeOffer(request, suom));
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
@PostMapping("/upgradeOffer/changeOrderPricing")
|
|
|
275 |
public ResponseEntity<ApiResponse<?>> changeOrderPricing(HttpServletRequest request,
|
|
|
276 |
@RequestParam String imei,
|
|
|
277 |
@RequestParam int totalPayout) throws Throwable {
|
|
|
278 |
return wrapResponse(orderController.changeOrderPricing(request, imei, totalPayout));
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
@GetMapping("/insurance/checkInsurance")
|
|
|
282 |
public ResponseEntity<ApiResponse<?>> checkInsurance(HttpServletRequest request,
|
|
|
283 |
@RequestParam String imei) throws Throwable {
|
|
|
284 |
return wrapResponse(orderController.checkInsurance(request, imei));
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
@GetMapping("/insurance/checkplans")
|
|
|
288 |
public ResponseEntity<ApiResponse<?>> getInsurancePrices(HttpServletRequest request,
|
|
|
289 |
@RequestParam float price,
|
|
|
290 |
@RequestParam int itemId,
|
|
|
291 |
@RequestParam String createdDate) throws Throwable {
|
| 36391 |
aman |
292 |
LocalDateTime createDate = createdDate.contains("T")
|
|
|
293 |
? LocalDateTime.parse(createdDate)
|
|
|
294 |
: LocalDate.parse(createdDate).atStartOfDay();
|
| 36390 |
aman |
295 |
return wrapResponse(orderController.getInsurancePrices(request, price, itemId, String.valueOf(createDate)));
|
| 36321 |
vikas |
296 |
}
|
|
|
297 |
|
|
|
298 |
@PostMapping("/create-insurance")
|
|
|
299 |
public ResponseEntity<ApiResponse<?>> createInsurance(HttpServletRequest request,
|
|
|
300 |
@RequestBody InsuranceModel insuranceModel,
|
|
|
301 |
Model model) throws Throwable {
|
|
|
302 |
return wrapResponse(orderController.createInsurance(request, insuranceModel, model));
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
@GetMapping("/order/generateInvoice")
|
|
|
306 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request,
|
|
|
307 |
@RequestParam(name = "invoiceNumber") String invoiceNumber) throws Throwable {
|
|
|
308 |
// Returns PDF binary - pass through directly, cannot wrap in ApiResponse
|
|
|
309 |
return orderController.generateInvoice(request, invoiceNumber);
|
|
|
310 |
}
|
|
|
311 |
}
|