| 21612 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.util.HashSet;
|
|
|
4 |
import java.util.Set;
|
|
|
5 |
|
|
|
6 |
import javax.servlet.http.HttpServletRequest;
|
|
|
7 |
|
|
|
8 |
import org.slf4j.Logger;
|
|
|
9 |
import org.slf4j.LoggerFactory;
|
|
|
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
11 |
import org.springframework.stereotype.Controller;
|
|
|
12 |
import org.springframework.ui.Model;
|
|
|
13 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
14 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
15 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
16 |
|
|
|
17 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
18 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
19 |
import com.spice.profitmandi.dao.repository.InventoryItemRepository;
|
|
|
20 |
import com.spice.profitmandi.dao.repository.OrderRepository;
|
|
|
21 |
import com.spice.profitmandi.web.model.FofoDetails;
|
|
|
22 |
import com.spice.profitmandi.web.request.CreateOrderRequest;
|
|
|
23 |
import com.spice.profitmandi.web.request.CustomPaymentOption;
|
|
|
24 |
import com.spice.profitmandi.web.util.CookiesFetcher;
|
|
|
25 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
26 |
|
|
|
27 |
@Controller
|
|
|
28 |
public class OrderController {
|
|
|
29 |
|
|
|
30 |
private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
|
|
|
31 |
|
|
|
32 |
@Autowired
|
|
|
33 |
OrderRepository orderRepository;
|
|
|
34 |
|
|
|
35 |
@Autowired
|
|
|
36 |
InventoryItemRepository inventoryItemRepository;
|
|
|
37 |
|
|
|
38 |
@Autowired
|
|
|
39 |
MVCResponseSender mvcResponseSender;
|
|
|
40 |
|
|
|
41 |
@Autowired
|
|
|
42 |
CookiesFetcher cookiesFetcher;
|
|
|
43 |
|
|
|
44 |
@RequestMapping(value = "/order", method = RequestMethod.POST)
|
|
|
45 |
public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest, Model model) throws Throwable{
|
|
|
46 |
FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
|
|
47 |
|
|
|
48 |
return null;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
private void validatePaymentOptions(Set<CustomPaymentOption> customPaymentOptions, float totalAmount) throws ProfitMandiBusinessException
|
|
|
52 |
{
|
|
|
53 |
float calculatedAmount = 0;
|
|
|
54 |
Set<String> paymentOptionTypes = new HashSet<>();
|
|
|
55 |
for(CustomPaymentOption customPaymentOption : customPaymentOptions){
|
|
|
56 |
if(!paymentOptionTypes.add(customPaymentOption.getType().name())){
|
|
|
57 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_TYPE, customPaymentOption.getType().name(), "");
|
|
|
58 |
}
|
|
|
59 |
calculatedAmount = calculatedAmount + customPaymentOption.getAmount();
|
|
|
60 |
}
|
|
|
61 |
if(calculatedAmount != totalAmount){
|
|
|
62 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_CALCULATED_AMOUNT, calculatedAmount, "");
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
}
|