| Line 6... |
Line 6... |
| 6 |
import java.util.List;
|
6 |
import java.util.List;
|
| 7 |
import java.util.Map;
|
7 |
import java.util.Map;
|
| 8 |
|
8 |
|
| 9 |
import javax.servlet.http.HttpServletRequest;
|
9 |
import javax.servlet.http.HttpServletRequest;
|
| 10 |
|
10 |
|
| - |
|
11 |
import org.apache.commons.lang.ArrayUtils;
|
| 11 |
import org.slf4j.Logger;
|
12 |
import org.slf4j.Logger;
|
| 12 |
import org.slf4j.LoggerFactory;
|
13 |
import org.slf4j.LoggerFactory;
|
| - |
|
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 13 |
import org.springframework.beans.factory.annotation.Value;
|
15 |
import org.springframework.beans.factory.annotation.Value;
|
| 14 |
import org.springframework.http.HttpStatus;
|
16 |
import org.springframework.http.HttpStatus;
|
| 15 |
import org.springframework.http.MediaType;
|
17 |
import org.springframework.http.MediaType;
|
| 16 |
import org.springframework.http.ResponseEntity;
|
18 |
import org.springframework.http.ResponseEntity;
|
| 17 |
import org.springframework.stereotype.Controller;
|
19 |
import org.springframework.stereotype.Controller;
|
| Line 30... |
Line 32... |
| 30 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
32 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 31 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
33 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 32 |
import com.spice.profitmandi.common.model.ProfitMandiResponse;
|
34 |
import com.spice.profitmandi.common.model.ProfitMandiResponse;
|
| 33 |
import com.spice.profitmandi.common.model.ResponseStatus;
|
35 |
import com.spice.profitmandi.common.model.ResponseStatus;
|
| 34 |
import com.spice.profitmandi.common.web.client.RestClient;
|
36 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| - |
|
37 |
import com.spice.profitmandi.dao.entity.catalog.Tag;
|
| - |
|
38 |
import com.spice.profitmandi.service.tag.TagService;
|
| 35 |
import com.spice.profitmandi.web.res.DealBrands;
|
39 |
import com.spice.profitmandi.web.res.DealBrands;
|
| 36 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
40 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
| 37 |
import com.spice.profitmandi.web.res.DealsResponse;
|
41 |
import com.spice.profitmandi.web.res.DealsResponse;
|
| 38 |
|
42 |
|
| 39 |
import io.swagger.annotations.ApiImplicitParam;
|
43 |
import io.swagger.annotations.ApiImplicitParam;
|
| Line 47... |
Line 51... |
| 47 |
|
51 |
|
| 48 |
@Value("${python.api.host}")
|
52 |
@Value("${python.api.host}")
|
| 49 |
private String host;
|
53 |
private String host;
|
| 50 |
@Value("${python.api.port}")
|
54 |
@Value("${python.api.port}")
|
| 51 |
private int port;
|
55 |
private int port;
|
| - |
|
56 |
|
| - |
|
57 |
@Autowired
|
| - |
|
58 |
private TagService tagService;
|
| 52 |
|
59 |
|
| 53 |
@RequestMapping(value = ProfitMandiConstants.URL_DEALS, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
60 |
@RequestMapping(value = ProfitMandiConstants.URL_DEALS, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
| 54 |
@ApiImplicitParams({
|
61 |
@ApiImplicitParams({
|
| 55 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
62 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
| 56 |
required = true, dataType = "string", paramType = "header")
|
63 |
required = true, dataType = "string", paramType = "header")
|
| Line 71... |
Line 78... |
| 71 |
params.put("categoryId", categoryId);
|
78 |
params.put("categoryId", categoryId);
|
| 72 |
params.put("direction", direction);
|
79 |
params.put("direction", direction);
|
| 73 |
params.put("sort", sort);
|
80 |
params.put("sort", sort);
|
| 74 |
params.put("filterData", filterData);
|
81 |
params.put("filterData", filterData);
|
| 75 |
params.put("source", "deals");
|
82 |
params.put("source", "deals");
|
| - |
|
83 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
| 76 |
List<Object> responseObject = new ArrayList<>();
|
84 |
List<Object> responseObject = new ArrayList<>();
|
| 77 |
try {
|
85 |
try {
|
| 78 |
response = rc.get(uri, params);
|
86 |
response = rc.get(uri, params);
|
| 79 |
} catch (Exception | ProfitMandiBusinessException e) {
|
87 |
} catch (Exception | ProfitMandiBusinessException e) {
|
| 80 |
logger.error("Unable to get deals",e);
|
88 |
logger.error("Unable to get deals",e);
|
| Line 95... |
Line 103... |
| 95 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, responseObject);
|
103 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, responseObject);
|
| 96 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
104 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
| 97 |
}
|
105 |
}
|
| 98 |
|
106 |
|
| 99 |
|
107 |
|
| - |
|
108 |
private String getCommaSeparateTags(int userId) {
|
| - |
|
109 |
List<Tag> tags = tagService.getTagsByRetailerId(userId);
|
| - |
|
110 |
List<String> tagIds = new ArrayList<>();
|
| - |
|
111 |
for (Tag tag : tags) {
|
| - |
|
112 |
tagIds.add(String.valueOf(tag.getId()));
|
| - |
|
113 |
}
|
| - |
|
114 |
return String.join(",", tagIds);
|
| - |
|
115 |
}
|
| - |
|
116 |
|
| - |
|
117 |
|
| 100 |
@RequestMapping(value = ProfitMandiConstants.URL_DEALS, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
118 |
@RequestMapping(value = "/online-deals", method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
| 101 |
@ApiImplicitParams({
|
119 |
@ApiImplicitParams({
|
| 102 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
120 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
| 103 |
required = true, dataType = "string", paramType = "header")
|
121 |
required = true, dataType = "string", paramType = "header")
|
| 104 |
})
|
122 |
})
|
| 105 |
@ApiOperation(value = "Get online deals")
|
123 |
@ApiOperation(value = "Get online deals")
|
| Line 118... |
Line 136... |
| 118 |
params.put("categoryId", categoryId);
|
136 |
params.put("categoryId", categoryId);
|
| 119 |
params.put("direction", direction);
|
137 |
params.put("direction", direction);
|
| 120 |
params.put("sort", sort);
|
138 |
params.put("sort", sort);
|
| 121 |
params.put("source", "online");
|
139 |
params.put("source", "online");
|
| 122 |
params.put("filterData", filterData);
|
140 |
params.put("filterData", filterData);
|
| - |
|
141 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
| 123 |
List<Object> responseObject = new ArrayList<>();
|
142 |
List<Object> responseObject = new ArrayList<>();
|
| 124 |
try {
|
143 |
try {
|
| 125 |
response = rc.get(uri, params);
|
144 |
response = rc.get(uri, params);
|
| 126 |
} catch (Exception | ProfitMandiBusinessException e) {
|
145 |
} catch (Exception | ProfitMandiBusinessException e) {
|
| 127 |
logger.error("Unable to get deals",e);
|
146 |
logger.error("Unable to get deals",e);
|