Subversion Repositories SmartDukaan

Rev

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