| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.v2.controller;
|
1 |
package com.spice.profitmandi.web.v2.controller;
|
| 2 |
|
2 |
|
| - |
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 3 |
import com.spice.profitmandi.common.model.SamsungUpgradeOfferModel;
|
4 |
import com.spice.profitmandi.common.model.SamsungUpgradeOfferModel;
|
| 4 |
import com.spice.profitmandi.common.model.CreateOrderRequest;
|
5 |
import com.spice.profitmandi.common.model.CreateOrderRequest;
|
| 5 |
import com.spice.profitmandi.common.model.InsuranceModel;
|
6 |
import com.spice.profitmandi.common.model.InsuranceModel;
|
| - |
|
7 |
import com.spice.profitmandi.dao.cart.CartService;
|
| - |
|
8 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| - |
|
9 |
import com.spice.profitmandi.dao.model.UserCart;
|
| - |
|
10 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| - |
|
11 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 6 |
import com.spice.profitmandi.web.controller.checkout.OrderController;
|
12 |
import com.spice.profitmandi.web.controller.checkout.OrderController;
|
| 7 |
import com.spice.profitmandi.web.v2.response.ApiResponse;
|
13 |
import com.spice.profitmandi.web.v2.response.ApiResponse;
|
| 8 |
import in.shop2020.model.v1.order.OrderStatus;
|
14 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 9 |
import org.springframework.beans.factory.annotation.Autowired;
|
15 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 10 |
import org.springframework.http.ResponseEntity;
|
16 |
import org.springframework.http.ResponseEntity;
|
| 11 |
import org.springframework.ui.Model;
|
17 |
import org.springframework.ui.Model;
|
| - |
|
18 |
import org.springframework.transaction.annotation.Transactional;
|
| 12 |
import org.springframework.web.bind.annotation.*;
|
19 |
import org.springframework.web.bind.annotation.*;
|
| 13 |
|
20 |
|
| 14 |
import javax.servlet.http.HttpServletRequest;
|
21 |
import javax.servlet.http.HttpServletRequest;
|
| 15 |
import javax.servlet.http.HttpServletResponse;
|
22 |
import javax.servlet.http.HttpServletResponse;
|
| - |
|
23 |
import java.time.LocalDateTime;
|
| 16 |
import java.time.YearMonth;
|
24 |
import java.time.YearMonth;
|
| 17 |
import java.util.List;
|
25 |
import java.util.List;
|
| 18 |
|
26 |
|
| 19 |
@RestController
|
27 |
@RestController
|
| 20 |
@RequestMapping("/v2")
|
28 |
@RequestMapping("/v2")
|
| - |
|
29 |
@Transactional(rollbackFor = Throwable.class)
|
| 21 |
public class V2OrderController extends V2BaseController {
|
30 |
public class V2OrderController extends V2BaseController {
|
| 22 |
|
31 |
|
| 23 |
@Autowired
|
32 |
@Autowired
|
| 24 |
private OrderController orderController;
|
33 |
private OrderController orderController;
|
| 25 |
|
34 |
|
| - |
|
35 |
@Autowired
|
| - |
|
36 |
private UserAccountRepository userAccountRepository;
|
| - |
|
37 |
|
| - |
|
38 |
@Autowired
|
| - |
|
39 |
private AddressRepository addressRepository;
|
| - |
|
40 |
|
| - |
|
41 |
@Autowired
|
| - |
|
42 |
private CartService cartService;
|
| - |
|
43 |
|
| 26 |
@RequestMapping(value = "/order/create", method = {RequestMethod.POST, RequestMethod.GET})
|
44 |
@RequestMapping(value = "/order/create", method = {RequestMethod.POST, RequestMethod.GET})
|
| 27 |
public ResponseEntity<ApiResponse<?>> createOrder(HttpServletRequest request,
|
45 |
public ResponseEntity<ApiResponse<?>> createOrder(HttpServletRequest request,
|
| 28 |
@RequestParam(value = "paymentOption") String paymentOption,
|
46 |
@RequestParam(value = "paymentOption") String paymentOption,
|
| 29 |
@RequestParam(value = "walletUsed") double walletUsed,
|
47 |
@RequestParam(value = "walletUsed") double walletUsed,
|
| 30 |
@RequestParam(value = "selfPickup", defaultValue = "false") boolean selfPickup,
|
48 |
@RequestParam(value = "selfPickup", defaultValue = "false") boolean selfPickup,
|
| 31 |
@RequestParam(defaultValue = "0") int freeCreditDays) throws Throwable {
|
49 |
@RequestParam(defaultValue = "0") int freeCreditDays,
|
| - |
|
50 |
@RequestParam(value = "reservationId", required = false) String reservationId) throws Throwable {
|
| 32 |
return wrapResponse(orderController.createOrder(request, paymentOption, walletUsed, selfPickup, freeCreditDays));
|
51 |
return wrapResponse(orderController.createOrder(request, paymentOption, walletUsed, selfPickup, freeCreditDays, reservationId));
|
| 33 |
}
|
52 |
}
|
| 34 |
|
53 |
|
| 35 |
// TODO: paymentOptions writes directly to response via void method - skipping v2 wrapper
|
54 |
// TODO: paymentOptions writes directly to response via void method - skipping v2 wrapper
|
| 36 |
// @GetMapping("/paymentOptions")
|
55 |
// @GetMapping("/paymentOptions")
|
| 37 |
|
56 |
|
| Line 100... |
Line 119... |
| 100 |
public ResponseEntity<ApiResponse<?>> getOrderListByOrderId(HttpServletRequest request,
|
119 |
public ResponseEntity<ApiResponse<?>> getOrderListByOrderId(HttpServletRequest request,
|
| 101 |
@RequestParam(name = "orderId") List<Integer> orderIds) throws Throwable {
|
120 |
@RequestParam(name = "orderId") List<Integer> orderIds) throws Throwable {
|
| 102 |
return wrapResponse(orderController.getOrderListByOrderId(request, orderIds));
|
121 |
return wrapResponse(orderController.getOrderListByOrderId(request, orderIds));
|
| 103 |
}
|
122 |
}
|
| 104 |
|
123 |
|
| - |
|
124 |
/**
|
| - |
|
125 |
* Direct-JPA address creation. Replaces the legacy
|
| - |
|
126 |
* {@link OrderController#createAddress} path, which went through the
|
| - |
|
127 |
* Thrift {@code UserClient} — that requires a remote config service
|
| - |
|
128 |
* (Consul/ZK) not available in every environment and was throwing NPE
|
| - |
|
129 |
* on {@code ConfigClient.getClient().get(...)}.
|
| - |
|
130 |
*/
|
| 105 |
@PostMapping("/address/create")
|
131 |
@PostMapping("/address/create")
|
| 106 |
public ResponseEntity<ApiResponse<?>> createAddress(HttpServletRequest request,
|
132 |
public ResponseEntity<ApiResponse<?>> createAddress(HttpServletRequest request,
|
| 107 |
@RequestBody in.shop2020.model.v1.user.Address address) throws Throwable {
|
133 |
@RequestBody in.shop2020.model.v1.user.Address body)
|
| - |
|
134 |
throws ProfitMandiBusinessException {
|
| - |
|
135 |
Object userIdAttr = request.getAttribute("userId");
|
| - |
|
136 |
if (!(userIdAttr instanceof Integer)) {
|
| - |
|
137 |
java.util.Map<String, Object> err = new java.util.HashMap<>();
|
| - |
|
138 |
err.put("responseStatus", "FAILURE");
|
| - |
|
139 |
err.put("statusCode", 401);
|
| - |
|
140 |
err.put("statusMessage", "LOGIN_REQUIRED");
|
| - |
|
141 |
return ResponseEntity.status(401).body(ApiResponse.success(err));
|
| - |
|
142 |
}
|
| - |
|
143 |
int userId = (int) userIdAttr;
|
| - |
|
144 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
| - |
|
145 |
if (uc == null) {
|
| - |
|
146 |
throw new ProfitMandiBusinessException("userId", userId, "USER_CART_NOT_FOUND");
|
| - |
|
147 |
}
|
| - |
|
148 |
|
| - |
|
149 |
Address entity = new Address();
|
| - |
|
150 |
entity.setName(body.getName());
|
| - |
|
151 |
entity.setLine1(body.getLine1());
|
| - |
|
152 |
entity.setLine2(body.getLine2());
|
| - |
|
153 |
entity.setLandmark(body.getLandmark());
|
| - |
|
154 |
entity.setCity(body.getCity());
|
| - |
|
155 |
entity.setState(body.getState());
|
| - |
|
156 |
entity.setPinCode(body.getPin());
|
| - |
|
157 |
entity.setCountry(body.getCountry() == null ? "India" : body.getCountry());
|
| - |
|
158 |
entity.setPhoneNumber(body.getPhone());
|
| - |
|
159 |
entity.setEnabled(true);
|
| - |
|
160 |
// Entity setter has a historical typo ("Retaier") — keep using it so
|
| - |
|
161 |
// we don't break every other caller. Renaming is out of scope here.
|
| - |
|
162 |
entity.setRetaierId(uc.getUserId());
|
| - |
|
163 |
entity.setCreateTimestamp(LocalDateTime.now());
|
| - |
|
164 |
entity.setUpdateTimestamp(LocalDateTime.now());
|
| - |
|
165 |
addressRepository.persist(entity);
|
| - |
|
166 |
|
| - |
|
167 |
// Bind the new address to the partner's cart so the very next
|
| - |
|
168 |
// /v2/cart/open call resolves pincode from it.
|
| - |
|
169 |
cartService.addAddressToCart(uc.getCartId(), entity.getId());
|
| - |
|
170 |
|
| 108 |
return wrapResponse(orderController.createAddress(request, address));
|
171 |
return ResponseEntity.ok(ApiResponse.success((long) entity.getId()));
|
| 109 |
}
|
172 |
}
|
| 110 |
|
173 |
|
| 111 |
// TODO: fetchOnlineOrders writes directly to response via void method - skipping v2 wrapper
|
174 |
// TODO: fetchOnlineOrders writes directly to response via void method - skipping v2 wrapper
|
| 112 |
// @GetMapping("/online-orders")
|
175 |
// @GetMapping("/online-orders")
|
| 113 |
|
176 |
|