| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
4 |
import com.spice.profitmandi.common.model.UserInfo;
|
| 4 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
5 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 5 |
import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
|
6 |
import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
|
| 6 |
import com.spice.profitmandi.dao.model.TodayOfferModel;
|
7 |
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;
|
8 |
import com.spice.profitmandi.service.catalog.BrandsService;
|
| 10 |
import com.spice.profitmandi.service.offers.TodayOfferService;
|
9 |
import com.spice.profitmandi.service.offers.TodayOfferService;
|
| 11 |
import org.apache.logging.log4j.LogManager;
|
10 |
import org.apache.logging.log4j.LogManager;
|
| 12 |
import org.apache.logging.log4j.Logger;
|
11 |
import org.apache.logging.log4j.Logger;
|
| 13 |
import org.springframework.beans.factory.annotation.Autowired;
|
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
| Line 37... |
Line 36... |
| 37 |
private BrandsService brandsService;
|
36 |
private BrandsService brandsService;
|
| 38 |
|
37 |
|
| 39 |
@Autowired
|
38 |
@Autowired
|
| 40 |
private TodayOfferService todayOfferService;
|
39 |
private TodayOfferService todayOfferService;
|
| 41 |
|
40 |
|
| 42 |
@Autowired
|
- |
|
| 43 |
private UserAccountRepository userAccountRepository;
|
- |
|
| 44 |
|
- |
|
| 45 |
@RequestMapping(value = "/todayOffers/brands", method = RequestMethod.GET)
|
41 |
@RequestMapping(value = "/todayOffers/brands", method = RequestMethod.GET)
|
| 46 |
public ResponseEntity<?> getTodayOfferBrands(HttpServletRequest request) throws ProfitMandiBusinessException {
|
42 |
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"));
|
43 |
List<String> brands = new ArrayList<>(Arrays.asList("Vivo","Oppo","Samsung","Xiaomi","Realme","Apple","Itel","Motorola","Poco","Tecno"));
|
| 48 |
return responseSender.ok(brands);
|
44 |
return responseSender.ok(brands);
|
| 49 |
}
|
45 |
}
|
| 50 |
|
46 |
|
| 51 |
@RequestMapping(value = "/todayOffers", method = RequestMethod.GET)
|
47 |
@RequestMapping(value = "/todayOffers", method = RequestMethod.GET)
|
| 52 |
public ResponseEntity<?> getTodayOffers(HttpServletRequest request, @RequestParam String brand) throws ProfitMandiBusinessException {
|
48 |
public ResponseEntity<?> getTodayOffers(HttpServletRequest request, @RequestParam String brand) throws ProfitMandiBusinessException {
|
| 53 |
int userId = (int) request.getAttribute("userId");
|
49 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 54 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
- |
|
| 55 |
int fofoId = uc.getUserId();
|
50 |
int fofoId = userInfo.getRetailerId();
|
| 56 |
logger.info("todayOffers fofoId: {}", fofoId);
|
51 |
logger.info("todayOffers fofoId: {}", fofoId);
|
| - |
|
52 |
if (fofoId <= 0) {
|
| - |
|
53 |
return responseSender.ok(new ArrayList<>());
|
| - |
|
54 |
}
|
| 57 |
List<TodayOfferModel> todayOfferModels = todayOfferService.findAllTodayOffer(brand, fofoId);
|
55 |
List<TodayOfferModel> todayOfferModels = todayOfferService.findAllTodayOffer(brand, fofoId);
|
| 58 |
List<TodayOfferModel> groupedOffers = todayOfferService.groupSameOffers(todayOfferModels);
|
56 |
List<TodayOfferModel> groupedOffers = todayOfferService.groupSameOffers(todayOfferModels);
|
| 59 |
logger.info("groupedOffers size: {}", groupedOffers.size());
|
57 |
logger.info("groupedOffers size: {}", groupedOffers.size());
|
| 60 |
return responseSender.ok(groupedOffers);
|
58 |
return responseSender.ok(groupedOffers);
|
| 61 |
}
|
59 |
}
|