| 35727 |
vikas |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
4 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
|
|
5 |
import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
|
|
|
6 |
import com.spice.profitmandi.dao.model.TodayOfferModel;
|
|
|
7 |
import com.spice.profitmandi.dao.model.UserCart;
|
|
|
8 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
9 |
import com.spice.profitmandi.service.catalog.BrandsService;
|
|
|
10 |
import com.spice.profitmandi.service.offers.TodayOfferService;
|
|
|
11 |
import org.apache.logging.log4j.LogManager;
|
|
|
12 |
import org.apache.logging.log4j.Logger;
|
|
|
13 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
14 |
import org.springframework.http.ResponseEntity;
|
|
|
15 |
import org.springframework.stereotype.Controller;
|
|
|
16 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
17 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
18 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
19 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
20 |
|
|
|
21 |
import javax.servlet.http.HttpServletRequest;
|
|
|
22 |
import java.util.ArrayList;
|
|
|
23 |
import java.util.Arrays;
|
|
|
24 |
import java.util.List;
|
|
|
25 |
import java.util.stream.Collectors;
|
|
|
26 |
|
|
|
27 |
@Controller
|
|
|
28 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
29 |
public class TodayOfferController {
|
|
|
30 |
|
|
|
31 |
private static final Logger logger = LogManager.getLogger(TodayOfferController.class);
|
|
|
32 |
|
|
|
33 |
@Autowired
|
|
|
34 |
private ResponseSender responseSender;
|
|
|
35 |
|
|
|
36 |
@Autowired
|
|
|
37 |
private BrandsService brandsService;
|
|
|
38 |
|
|
|
39 |
@Autowired
|
|
|
40 |
private TodayOfferService todayOfferService;
|
|
|
41 |
|
|
|
42 |
@Autowired
|
|
|
43 |
private UserAccountRepository userAccountRepository;
|
|
|
44 |
|
|
|
45 |
@RequestMapping(value = "/todayOffers/brands", method = RequestMethod.GET)
|
|
|
46 |
public ResponseEntity<?> getTodayOfferBrands(HttpServletRequest request) throws ProfitMandiBusinessException {
|
|
|
47 |
List<String> brands = new ArrayList<>(Arrays.asList("Vivo","Oppo","Samsung","Xiaomi","Realme","Apple","Itel","Motorola","Poco","Tecno"));
|
|
|
48 |
return responseSender.ok(brands);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
@RequestMapping(value = "/todayOffers", method = RequestMethod.GET)
|
|
|
52 |
public ResponseEntity<?> getTodayOffers(HttpServletRequest request, @RequestParam String brand) throws ProfitMandiBusinessException {
|
|
|
53 |
int userId = (int) request.getAttribute("userId");
|
|
|
54 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
55 |
int fofoId = uc.getUserId();
|
|
|
56 |
logger.info("todayOffers fofoId: {}", fofoId);
|
|
|
57 |
List<TodayOfferModel> todayOfferModels = todayOfferService.findAllTodayOffer(brand, fofoId);
|
|
|
58 |
List<TodayOfferModel> groupedOffers = todayOfferService.groupSameOffers(todayOfferModels);
|
|
|
59 |
logger.info("groupedOffers size: {}", groupedOffers.size());
|
|
|
60 |
return responseSender.ok(groupedOffers);
|
|
|
61 |
}
|
|
|
62 |
}
|