Rev 21680 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.controller;import java.util.HashSet;import java.util.Set;import javax.servlet.http.HttpServletRequest;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.common.model.ProfitMandiConstants;import com.spice.profitmandi.dao.repository.InventoryItemRepository;import com.spice.profitmandi.dao.repository.OrderRepository;import com.spice.profitmandi.web.model.FofoDetails;import com.spice.profitmandi.web.request.CreateOrderRequest;import com.spice.profitmandi.web.request.CustomPaymentOption;import com.spice.profitmandi.web.util.CookiesFetcher;import com.spice.profitmandi.web.util.MVCResponseSender;@Controllerpublic class OrderController {private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);@AutowiredOrderRepository orderRepository;@AutowiredInventoryItemRepository inventoryItemRepository;@AutowiredMVCResponseSender mvcResponseSender;@AutowiredCookiesFetcher cookiesFetcher;@RequestMapping(value = "/order", method = RequestMethod.POST)public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest, Model model) throws Throwable{FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);return null;}private void validatePaymentOptions(Set<CustomPaymentOption> customPaymentOptions, float totalAmount) throws ProfitMandiBusinessException{float calculatedAmount = 0;Set<String> paymentOptionTypes = new HashSet<>();for(CustomPaymentOption customPaymentOption : customPaymentOptions){if(!paymentOptionTypes.add(customPaymentOption.getType().name())){throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_TYPE, customPaymentOption.getType().name(), "");}calculatedAmount = calculatedAmount + customPaymentOption.getAmount();}if(calculatedAmount != totalAmount){throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_CALCULATED_AMOUNT, calculatedAmount, "");}}}