| 21339 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
| 22336 |
amit.gupta |
4 |
import java.util.Arrays;
|
| 21339 |
kshitij.so |
5 |
import java.util.HashMap;
|
| 22952 |
amit.gupta |
6 |
import java.util.Iterator;
|
| 21339 |
kshitij.so |
7 |
import java.util.List;
|
|
|
8 |
import java.util.Map;
|
|
|
9 |
|
|
|
10 |
import javax.servlet.http.HttpServletRequest;
|
|
|
11 |
|
| 22319 |
amit.gupta |
12 |
import org.apache.commons.lang3.StringUtils;
|
| 23532 |
amit.gupta |
13 |
import org.apache.http.conn.HttpHostConnectException;
|
| 22319 |
amit.gupta |
14 |
import org.json.JSONArray;
|
|
|
15 |
import org.json.JSONObject;
|
| 23568 |
govind |
16 |
import org.apache.logging.log4j.Logger;
|
|
|
17 |
import org.apache.logging.log4j.LogManager;
|
| 22273 |
amit.gupta |
18 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21339 |
kshitij.so |
19 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
20 |
import org.springframework.http.HttpStatus;
|
|
|
21 |
import org.springframework.http.MediaType;
|
|
|
22 |
import org.springframework.http.ResponseEntity;
|
|
|
23 |
import org.springframework.stereotype.Controller;
|
| 22286 |
amit.gupta |
24 |
import org.springframework.transaction.annotation.Transactional;
|
| 21339 |
kshitij.so |
25 |
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
26 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
27 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
28 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
29 |
|
|
|
30 |
import com.eclipsesource.json.Json;
|
|
|
31 |
import com.eclipsesource.json.JsonArray;
|
|
|
32 |
import com.eclipsesource.json.JsonObject;
|
|
|
33 |
import com.eclipsesource.json.JsonValue;
|
|
|
34 |
import com.google.gson.Gson;
|
| 21356 |
kshitij.so |
35 |
import com.google.gson.reflect.TypeToken;
|
| 21643 |
ashik.ali |
36 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 21339 |
kshitij.so |
37 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
38 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22289 |
amit.gupta |
39 |
import com.spice.profitmandi.common.model.UserInfo;
|
| 21643 |
ashik.ali |
40 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 22319 |
amit.gupta |
41 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 23426 |
amit.gupta |
42 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 22289 |
amit.gupta |
43 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 22361 |
amit.gupta |
44 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 23426 |
amit.gupta |
45 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 22333 |
amit.gupta |
46 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 22361 |
amit.gupta |
47 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 22989 |
amit.gupta |
48 |
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
|
| 22931 |
ashik.ali |
49 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 22287 |
amit.gupta |
50 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| 22952 |
amit.gupta |
51 |
import com.spice.profitmandi.web.res.AvailabilityInfo;
|
| 21356 |
kshitij.so |
52 |
import com.spice.profitmandi.web.res.DealBrands;
|
| 21339 |
kshitij.so |
53 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
|
|
54 |
import com.spice.profitmandi.web.res.DealsResponse;
|
| 22328 |
amit.gupta |
55 |
import com.spice.profitmandi.web.res.FofoAvailabilityInfo;
|
|
|
56 |
import com.spice.profitmandi.web.res.FofoCatalogResponse;
|
| 21339 |
kshitij.so |
57 |
|
|
|
58 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
59 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
60 |
import io.swagger.annotations.ApiOperation;
|
|
|
61 |
|
|
|
62 |
@Controller
|
| 22319 |
amit.gupta |
63 |
@Transactional(rollbackFor = Throwable.class)
|
| 21339 |
kshitij.so |
64 |
public class DealsController {
|
|
|
65 |
|
| 23568 |
govind |
66 |
private static final Logger logger = LogManager.getLogger(DealsController.class);
|
| 21339 |
kshitij.so |
67 |
|
|
|
68 |
@Value("${python.api.host}")
|
|
|
69 |
private String host;
|
| 22931 |
ashik.ali |
70 |
|
| 21339 |
kshitij.so |
71 |
@Value("${python.api.port}")
|
|
|
72 |
private int port;
|
| 22708 |
amit.gupta |
73 |
|
| 22989 |
amit.gupta |
74 |
//This is now unused as we are not supporting multiple companies.
|
| 23300 |
amit.gupta |
75 |
@Value("${gadgetCops.invoice.cc}")
|
|
|
76 |
private String[] ccGadgetCopInvoiceTo;
|
| 22319 |
amit.gupta |
77 |
|
|
|
78 |
@Autowired
|
|
|
79 |
private PricingService pricingService;
|
| 22273 |
amit.gupta |
80 |
|
|
|
81 |
@Autowired
|
| 22333 |
amit.gupta |
82 |
private Mongo mongoClient;
|
|
|
83 |
|
|
|
84 |
@Autowired
|
| 22361 |
amit.gupta |
85 |
private UserAccountRepository userAccountRepository;
|
|
|
86 |
|
|
|
87 |
@Autowired
|
| 22989 |
amit.gupta |
88 |
private ItemAvailabilityCacheRepository itemAvailabilityCacheRepository;
|
|
|
89 |
|
|
|
90 |
@Autowired
|
| 22931 |
ashik.ali |
91 |
private ResponseSender<?> responseSender;
|
| 22336 |
amit.gupta |
92 |
|
| 22554 |
amit.gupta |
93 |
@Autowired
|
| 22931 |
ashik.ali |
94 |
private InventoryService inventoryService;
|
| 22401 |
amit.gupta |
95 |
|
| 23426 |
amit.gupta |
96 |
@Autowired
|
|
|
97 |
private ItemRepository itemRepository;
|
| 22554 |
amit.gupta |
98 |
|
| 23426 |
amit.gupta |
99 |
|
| 22336 |
amit.gupta |
100 |
List<String> filterableParams = Arrays.asList("brand");
|
| 21339 |
kshitij.so |
101 |
|
| 22319 |
amit.gupta |
102 |
@RequestMapping(value = ProfitMandiConstants.URL_DEALS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21339 |
kshitij.so |
103 |
@ApiImplicitParams({
|
| 22319 |
amit.gupta |
104 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 21339 |
kshitij.so |
105 |
@ApiOperation(value = "Get deals")
|
| 22319 |
amit.gupta |
106 |
public ResponseEntity<?> getDeals(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
|
|
|
107 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
|
|
108 |
@RequestParam(value = "sort", required = false) String sort,
|
|
|
109 |
@RequestParam(value = "direction", required = false) String direction,
|
| 22931 |
ashik.ali |
110 |
@RequestParam(value = "filterData", required = false) String filterData) throws ProfitMandiBusinessException {
|
| 22319 |
amit.gupta |
111 |
logger.info("Request " + request.getParameterMap());
|
| 21339 |
kshitij.so |
112 |
String response = null;
|
| 22319 |
amit.gupta |
113 |
int userId = (int) request.getAttribute("userId");
|
| 22988 |
amit.gupta |
114 |
|
|
|
115 |
//If pincode belongs to Specific warehouse marked
|
|
|
116 |
//availability should be fetched for that warehouse only
|
|
|
117 |
//show only skus belonging to that specific
|
|
|
118 |
//else use normal flow
|
| 22319 |
amit.gupta |
119 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
120 |
// TODO: move to properties
|
|
|
121 |
String uri = "/deals/" + userId;
|
| 23532 |
amit.gupta |
122 |
RestClient rc = new RestClient();
|
| 21339 |
kshitij.so |
123 |
Map<String, String> params = new HashMap<>();
|
|
|
124 |
params.put("offset", offset);
|
|
|
125 |
params.put("limit", limit);
|
|
|
126 |
params.put("categoryId", categoryId);
|
|
|
127 |
params.put("direction", direction);
|
|
|
128 |
params.put("sort", sort);
|
|
|
129 |
params.put("filterData", filterData);
|
| 22272 |
amit.gupta |
130 |
params.put("source", "deals");
|
| 22319 |
amit.gupta |
131 |
if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
| 22289 |
amit.gupta |
132 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
|
|
133 |
}
|
| 21356 |
kshitij.so |
134 |
List<Object> responseObject = new ArrayList<>();
|
| 23532 |
amit.gupta |
135 |
try {
|
|
|
136 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
|
|
137 |
} catch (HttpHostConnectException e) {
|
|
|
138 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
139 |
}
|
| 22931 |
ashik.ali |
140 |
|
| 21339 |
kshitij.so |
141 |
JsonArray result_json = Json.parse(response).asArray();
|
| 22319 |
amit.gupta |
142 |
for (JsonValue j : result_json) {
|
| 22842 |
amit.gupta |
143 |
//logger.info("res " + j.asArray());
|
| 21339 |
kshitij.so |
144 |
List<Object> innerObject = new ArrayList<>();
|
| 22319 |
amit.gupta |
145 |
for (JsonValue jsonObject : j.asArray()) {
|
| 21356 |
kshitij.so |
146 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
| 21339 |
kshitij.so |
147 |
}
|
| 22319 |
amit.gupta |
148 |
if (innerObject.size() > 0) {
|
| 21339 |
kshitij.so |
149 |
responseObject.add(innerObject);
|
|
|
150 |
}
|
|
|
151 |
}
|
| 23022 |
ashik.ali |
152 |
return responseSender.ok(responseObject);
|
| 21339 |
kshitij.so |
153 |
}
|
|
|
154 |
|
| 22931 |
ashik.ali |
155 |
private String getCommaSeparateTags(int userId){
|
| 22361 |
amit.gupta |
156 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
157 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
| 22287 |
amit.gupta |
158 |
List<String> strTagIds = new ArrayList<>();
|
|
|
159 |
for (Integer tagId : tagIds) {
|
|
|
160 |
strTagIds.add(String.valueOf(tagId));
|
| 22273 |
amit.gupta |
161 |
}
|
| 22287 |
amit.gupta |
162 |
return String.join(",", strTagIds);
|
| 22273 |
amit.gupta |
163 |
}
|
|
|
164 |
|
| 22319 |
amit.gupta |
165 |
@ApiImplicitParams({
|
|
|
166 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
167 |
@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
168 |
public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
|
|
|
169 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
| 22336 |
amit.gupta |
170 |
@RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "brand", required = false) String brand) throws Throwable {
|
| 22328 |
amit.gupta |
171 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
| 22319 |
amit.gupta |
172 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
173 |
if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
| 22361 |
amit.gupta |
174 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
|
|
175 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
| 23532 |
amit.gupta |
176 |
RestClient rc = new RestClient();
|
| 22319 |
amit.gupta |
177 |
Map<String, String> params = new HashMap<>();
|
| 22336 |
amit.gupta |
178 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
179 |
if(brand != null) {
|
| 22347 |
amit.gupta |
180 |
|
| 22348 |
amit.gupta |
181 |
mandatoryQ.add(String.format("+{!parent which=\"brand_s=%s\"} tagId_i:(%s)", brand, StringUtils.join(tagIds, " ")));
|
| 22347 |
amit.gupta |
182 |
} else {
|
|
|
183 |
mandatoryQ.add(String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
|
| 22336 |
amit.gupta |
184 |
}
|
| 22340 |
amit.gupta |
185 |
params.put("q", StringUtils.join(mandatoryQ," "));
|
| 22319 |
amit.gupta |
186 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
|
|
187 |
params.put("sort", "rank_i asc");
|
|
|
188 |
params.put("start", String.valueOf(offset));
|
|
|
189 |
params.put("rows", String.valueOf(limit));
|
|
|
190 |
params.put("wt", "json");
|
| 23532 |
amit.gupta |
191 |
String response = null;
|
|
|
192 |
try {
|
|
|
193 |
response =rc.get(SchemeType.HTTP, "dtr", 8984, "solr/demo/select", params);
|
|
|
194 |
} catch (HttpHostConnectException e) {
|
|
|
195 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
196 |
}
|
| 22319 |
amit.gupta |
197 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
198 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
|
|
199 |
for(int i=0; i < docs.length(); i++) {
|
| 22328 |
amit.gupta |
200 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
| 22319 |
amit.gupta |
201 |
JSONObject doc = docs.getJSONObject(i);
|
| 22328 |
amit.gupta |
202 |
FofoCatalogResponse ffdr = new FofoCatalogResponse();
|
| 22319 |
amit.gupta |
203 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
|
|
204 |
ffdr.setImageUrl(doc.getString("imageUrl_s"));
|
|
|
205 |
ffdr.setTitle(doc.getString("title_s"));
|
| 22333 |
amit.gupta |
206 |
ffdr.setBrand(doc.getString("brand_s"));
|
| 22323 |
amit.gupta |
207 |
for(int j=0; j< doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
208 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
| 22319 |
amit.gupta |
209 |
int itemId = childItem.getInt("itemId_i");
|
|
|
210 |
float sellingPrice = (float)childItem.getDouble("sellingPrice_f");
|
| 22328 |
amit.gupta |
211 |
if(fofoAvailabilityInfoMap.containsKey(itemId)) {
|
|
|
212 |
if(fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
|
|
213 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
|
|
214 |
fofoAvailabilityInfoMap.get(itemId).setMop((float)childItem.getDouble("mop_f"));
|
| 22319 |
amit.gupta |
215 |
}
|
|
|
216 |
} else {
|
| 22328 |
amit.gupta |
217 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
| 22319 |
amit.gupta |
218 |
fdi.setSellingPrice((float)childItem.getDouble("sellingPrice_f"));
|
|
|
219 |
fdi.setMop((float)childItem.getDouble("mop_f"));
|
| 22324 |
amit.gupta |
220 |
fdi.setColor(childItem.has("color_s")?childItem.getString("color_s"): "");
|
| 22319 |
amit.gupta |
221 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
| 22328 |
amit.gupta |
222 |
fdi.setItem_id(itemId);
|
| 23404 |
amit.gupta |
223 |
/*int totalAvailability = 0;
|
| 22989 |
amit.gupta |
224 |
//Using item availability cache for now but can be changed to use caching later.
|
|
|
225 |
try {
|
|
|
226 |
ItemAvailabilityCache iac = itemAvailabilityCacheRepository.selectByItemId(itemId);
|
|
|
227 |
totalAvailability = iac.getTotalAvailability();
|
|
|
228 |
} catch (Exception e) {}
|
| 22990 |
amit.gupta |
229 |
if(totalAvailability <= 0){
|
|
|
230 |
continue;
|
| 23404 |
amit.gupta |
231 |
}*/
|
| 23426 |
amit.gupta |
232 |
Item item = itemRepository.selectById(itemId);
|
|
|
233 |
//In case its tampered glass moq should be 5
|
|
|
234 |
if(item.getCategoryId()==10020) {
|
|
|
235 |
fdi.setMinBuyQuantity(5);
|
|
|
236 |
} else {
|
|
|
237 |
fdi.setMinBuyQuantity(1);
|
|
|
238 |
}
|
| 23404 |
amit.gupta |
239 |
fdi.setAvailability(10);
|
| 22328 |
amit.gupta |
240 |
fdi.setQuantityStep(1);
|
| 22561 |
amit.gupta |
241 |
fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
|
| 22990 |
amit.gupta |
242 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
| 22319 |
amit.gupta |
243 |
}
|
|
|
244 |
}
|
| 22988 |
amit.gupta |
245 |
if(fofoAvailabilityInfoMap.values().size() > 0) {
|
|
|
246 |
ffdr.setItems(new ArrayList<FofoAvailabilityInfo>(fofoAvailabilityInfoMap.values()));
|
|
|
247 |
dealResponse.add(ffdr);
|
|
|
248 |
}
|
| 22319 |
amit.gupta |
249 |
}
|
|
|
250 |
|
|
|
251 |
} else {
|
|
|
252 |
return responseSender.badRequest(new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
|
|
|
253 |
}
|
|
|
254 |
return responseSender.ok(dealResponse);
|
|
|
255 |
}
|
| 22273 |
amit.gupta |
256 |
|
| 22319 |
amit.gupta |
257 |
@RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 22272 |
amit.gupta |
258 |
@ApiImplicitParams({
|
| 22319 |
amit.gupta |
259 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 22272 |
amit.gupta |
260 |
@ApiOperation(value = "Get online deals")
|
| 22319 |
amit.gupta |
261 |
public ResponseEntity<?> getOnlineDeals(HttpServletRequest request,
|
|
|
262 |
@RequestParam(value = "categoryId") String categoryId, @RequestParam(value = "offset") String offset,
|
|
|
263 |
@RequestParam(value = "limit") String limit, @RequestParam(value = "sort", required = false) String sort,
|
|
|
264 |
@RequestParam(value = "direction", required = false) String direction,
|
|
|
265 |
@RequestParam(value = "filterData", required = false) String filterData) throws Throwable {
|
|
|
266 |
logger.info("Request " + request.getParameterMap());
|
| 22272 |
amit.gupta |
267 |
String response = null;
|
| 22319 |
amit.gupta |
268 |
int userId = (int) request.getAttribute("userId");
|
| 22289 |
amit.gupta |
269 |
|
| 22319 |
amit.gupta |
270 |
String uri = "/deals/" + userId;
|
| 23532 |
amit.gupta |
271 |
RestClient rc = new RestClient();
|
| 22272 |
amit.gupta |
272 |
Map<String, String> params = new HashMap<>();
|
|
|
273 |
params.put("offset", offset);
|
|
|
274 |
params.put("limit", limit);
|
|
|
275 |
params.put("categoryId", categoryId);
|
|
|
276 |
params.put("direction", direction);
|
|
|
277 |
params.put("sort", sort);
|
|
|
278 |
params.put("source", "online");
|
|
|
279 |
params.put("filterData", filterData);
|
| 22357 |
amit.gupta |
280 |
/*if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
| 22289 |
amit.gupta |
281 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
| 22357 |
amit.gupta |
282 |
}*/
|
| 22272 |
amit.gupta |
283 |
List<Object> responseObject = new ArrayList<>();
|
| 23532 |
amit.gupta |
284 |
try {
|
|
|
285 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
|
|
286 |
} catch (HttpHostConnectException e) {
|
|
|
287 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
288 |
}
|
| 22931 |
ashik.ali |
289 |
|
| 22272 |
amit.gupta |
290 |
JsonArray result_json = Json.parse(response).asArray();
|
| 22319 |
amit.gupta |
291 |
for (JsonValue j : result_json) {
|
| 22843 |
amit.gupta |
292 |
//logger.info("res " + j.asArray());
|
| 22272 |
amit.gupta |
293 |
List<Object> innerObject = new ArrayList<>();
|
| 22319 |
amit.gupta |
294 |
for (JsonValue jsonObject : j.asArray()) {
|
| 22272 |
amit.gupta |
295 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
|
|
296 |
}
|
| 22319 |
amit.gupta |
297 |
if (innerObject.size() > 0) {
|
| 22272 |
amit.gupta |
298 |
responseObject.add(innerObject);
|
|
|
299 |
}
|
|
|
300 |
}
|
| 23022 |
ashik.ali |
301 |
return responseSender.ok(responseObject);
|
| 22272 |
amit.gupta |
302 |
}
|
|
|
303 |
|
| 22319 |
amit.gupta |
304 |
/*
|
|
|
305 |
* @RequestMapping(value = "/direct-deals",
|
|
|
306 |
* method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
307 |
*
|
|
|
308 |
* @ApiImplicitParams({
|
|
|
309 |
*
|
|
|
310 |
* @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required =
|
|
|
311 |
* true, dataType = "string", paramType = "header") }) public
|
|
|
312 |
* ResponseEntity<?> getDirectDeals(HttpServletRequest
|
|
|
313 |
* request, @RequestParam(value="categoryId") String
|
|
|
314 |
* categoryId,@RequestParam(value="offset") String offset,
|
|
|
315 |
*
|
|
|
316 |
* @RequestParam(value="limit") String limit, @RequestParam(value="sort",
|
|
|
317 |
* required=false) String sort, @RequestParam(value="direction",
|
|
|
318 |
* required=false) String direction,
|
|
|
319 |
*
|
|
|
320 |
* @RequestParam(value="filterData", required=false) String filterData ){
|
|
|
321 |
*
|
|
|
322 |
* return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK); }
|
|
|
323 |
*/
|
|
|
324 |
|
|
|
325 |
private Object toDealObject(JsonObject jsonObject) {
|
|
|
326 |
if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
|
| 21339 |
kshitij.so |
327 |
return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
|
|
|
328 |
}
|
|
|
329 |
return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
|
|
|
330 |
}
|
| 22319 |
amit.gupta |
331 |
|
|
|
332 |
@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21356 |
kshitij.so |
333 |
@ApiImplicitParams({
|
| 22319 |
amit.gupta |
334 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 21356 |
kshitij.so |
335 |
@ApiOperation(value = "Get brand list and count for category")
|
| 22319 |
amit.gupta |
336 |
public ResponseEntity<?> getBrands(HttpServletRequest request,
|
| 22931 |
ashik.ali |
337 |
@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException{
|
| 22319 |
amit.gupta |
338 |
logger.info("Request " + request.getParameterMap());
|
| 21356 |
kshitij.so |
339 |
String response = null;
|
| 22319 |
amit.gupta |
340 |
// TODO: move to properties
|
| 21356 |
kshitij.so |
341 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
| 23532 |
amit.gupta |
342 |
RestClient rc = new RestClient();
|
| 21356 |
kshitij.so |
343 |
Map<String, String> params = new HashMap<>();
|
|
|
344 |
params.put("category_id", category_id);
|
| 21358 |
kshitij.so |
345 |
List<DealBrands> dealBrandsResponse = null;
|
| 23532 |
amit.gupta |
346 |
try {
|
|
|
347 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
|
|
348 |
} catch (HttpHostConnectException e) {
|
|
|
349 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
350 |
}
|
| 22931 |
ashik.ali |
351 |
|
| 22319 |
amit.gupta |
352 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
|
|
353 |
}.getType());
|
| 23022 |
ashik.ali |
354 |
|
|
|
355 |
return responseSender.ok(dealBrandsResponse);
|
| 21356 |
kshitij.so |
356 |
}
|
| 22319 |
amit.gupta |
357 |
|
|
|
358 |
@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21445 |
kshitij.so |
359 |
@ApiImplicitParams({
|
| 22319 |
amit.gupta |
360 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 21445 |
kshitij.so |
361 |
@ApiOperation(value = "Get unit deal object")
|
| 22931 |
ashik.ali |
362 |
public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
|
|
|
363 |
throws ProfitMandiBusinessException{
|
| 21445 |
kshitij.so |
364 |
String response = null;
|
| 22319 |
amit.gupta |
365 |
// TODO: move to properties
|
|
|
366 |
String uri = "getDealById/" + id;
|
|
|
367 |
System.out.println("Unit deal " + uri);
|
| 23532 |
amit.gupta |
368 |
RestClient rc = new RestClient();
|
| 21445 |
kshitij.so |
369 |
Map<String, String> params = new HashMap<>();
|
|
|
370 |
DealsResponse dealsResponse = null;
|
| 23532 |
amit.gupta |
371 |
try {
|
|
|
372 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
|
|
373 |
} catch (HttpHostConnectException e) {
|
|
|
374 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
375 |
}
|
| 22931 |
ashik.ali |
376 |
|
| 21445 |
kshitij.so |
377 |
JsonObject result_json = Json.parse(response).asObject();
|
| 22319 |
amit.gupta |
378 |
if (!result_json.isEmpty()) {
|
| 21445 |
kshitij.so |
379 |
dealsResponse = new Gson().fromJson(response, DealsResponse.class);
|
| 22952 |
amit.gupta |
380 |
Iterator<AvailabilityInfo> iter = dealsResponse.getAvailabilityInfo().iterator();
|
|
|
381 |
while (iter.hasNext()){
|
|
|
382 |
AvailabilityInfo ai = iter.next();
|
|
|
383 |
if(ai.getAvailability() <= 0)
|
|
|
384 |
iter.remove();
|
|
|
385 |
}
|
| 21445 |
kshitij.so |
386 |
}
|
| 22952 |
amit.gupta |
387 |
/*final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
| 22319 |
amit.gupta |
388 |
request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS,
|
| 22952 |
amit.gupta |
389 |
dealsResponse);*/
|
|
|
390 |
return responseSender.ok(dealsResponse);
|
| 21445 |
kshitij.so |
391 |
}
|
| 22333 |
amit.gupta |
392 |
|
|
|
393 |
@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
394 |
public ResponseEntity<?> getBrandsToDisplay() {
|
|
|
395 |
return new ResponseEntity<>(mongoClient.getBrandsToDisplay(), HttpStatus.OK);
|
|
|
396 |
}
|
| 22401 |
amit.gupta |
397 |
|
| 22446 |
amit.gupta |
398 |
@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 22448 |
amit.gupta |
399 |
public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
|
| 22447 |
amit.gupta |
400 |
return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
|
| 22446 |
amit.gupta |
401 |
}
|
|
|
402 |
|
| 22406 |
amit.gupta |
403 |
@ApiImplicitParams({
|
|
|
404 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 22401 |
amit.gupta |
405 |
@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 22931 |
ashik.ali |
406 |
public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
|
| 22401 |
amit.gupta |
407 |
StringBuffer sb = new StringBuffer("/getDealsForNotification/");
|
|
|
408 |
String uri = sb.append(skus).toString();
|
| 23532 |
amit.gupta |
409 |
RestClient rc = new RestClient();
|
|
|
410 |
String response;
|
|
|
411 |
try {
|
|
|
412 |
response = rc.get(SchemeType.HTTP, host, port, uri, new HashMap<>());
|
|
|
413 |
}catch (HttpHostConnectException e) {
|
|
|
414 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
415 |
}
|
| 22406 |
amit.gupta |
416 |
JsonArray result_json = Json.parse(response).asArray();
|
| 22407 |
amit.gupta |
417 |
List<Object> responseObject = new ArrayList<>();
|
|
|
418 |
for (JsonValue j : result_json) {
|
| 22843 |
amit.gupta |
419 |
//logger.info("res " + j.asArray());
|
| 22407 |
amit.gupta |
420 |
List<Object> innerObject = new ArrayList<>();
|
|
|
421 |
for (JsonValue jsonObject : j.asArray()) {
|
|
|
422 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
|
|
423 |
}
|
|
|
424 |
if (innerObject.size() > 0) {
|
|
|
425 |
responseObject.add(innerObject);
|
|
|
426 |
}
|
|
|
427 |
}
|
| 22408 |
amit.gupta |
428 |
return responseSender.ok(responseObject);
|
| 22401 |
amit.gupta |
429 |
}
|
| 21339 |
kshitij.so |
430 |
|
|
|
431 |
}
|