Subversion Repositories SmartDukaan

Rev

Rev 22447 | Rev 22554 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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