Subversion Repositories SmartDukaan

Rev

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