| Line 54... |
Line 54... |
| 54 |
@ApiImplicitParams({
|
54 |
@ApiImplicitParams({
|
| 55 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
55 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
| 56 |
required = true, dataType = "string", paramType = "header")
|
56 |
required = true, dataType = "string", paramType = "header")
|
| 57 |
})
|
57 |
})
|
| 58 |
@ApiOperation(value = "Get deals")
|
58 |
@ApiOperation(value = "Get deals")
|
| - |
|
59 |
public ResponseEntity<?> getDeals(HttpServletRequest request, @RequestParam(value="categoryId") String categoryId,
|
| 59 |
public ResponseEntity<?> getDeals(HttpServletRequest request, @RequestParam(value="categoryId") String categoryId,@RequestParam(value="offset") String offset, @RequestParam(value="limit") String limit, @RequestParam(value="sort", required=false) String sort, @RequestParam(value="direction", required=false) String direction, @RequestParam(value="filterData", required=false) String filterData ){
|
60 |
@RequestParam(value="offset") String offset, @RequestParam(value="limit") String limit, @RequestParam(value="sort", required=false) String sort,
|
| - |
|
61 |
@RequestParam(value="direction", required=false) String direction, @RequestParam(value="filterData", required=false) String filterData ){
|
| 60 |
logger.info("Request "+request.getParameterMap());
|
62 |
logger.info("Request "+request.getParameterMap());
|
| 61 |
String response = null;
|
63 |
String response = null;
|
| 62 |
int userId = (int)request.getAttribute("userId");
|
64 |
int userId = (int)request.getAttribute("userId");
|
| 63 |
//TODO: move to properties
|
65 |
//TODO: move to properties
|
| 64 |
String uri = "/deals/"+userId;
|
66 |
String uri = "/deals/"+userId;
|
| Line 68... |
Line 70... |
| 68 |
params.put("limit", limit);
|
70 |
params.put("limit", limit);
|
| 69 |
params.put("categoryId", categoryId);
|
71 |
params.put("categoryId", categoryId);
|
| 70 |
params.put("direction", direction);
|
72 |
params.put("direction", direction);
|
| 71 |
params.put("sort", sort);
|
73 |
params.put("sort", sort);
|
| 72 |
params.put("filterData", filterData);
|
74 |
params.put("filterData", filterData);
|
| - |
|
75 |
params.put("source", "deals");
|
| 73 |
List<Object> responseObject = new ArrayList<>();
|
76 |
List<Object> responseObject = new ArrayList<>();
|
| 74 |
try {
|
77 |
try {
|
| 75 |
response = rc.get(uri, params);
|
78 |
response = rc.get(uri, params);
|
| 76 |
} catch (Exception | ProfitMandiBusinessException e) {
|
79 |
} catch (Exception | ProfitMandiBusinessException e) {
|
| 77 |
logger.error("Unable to get deals",e);
|
80 |
logger.error("Unable to get deals",e);
|
| Line 91... |
Line 94... |
| 91 |
}
|
94 |
}
|
| 92 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, responseObject);
|
95 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, responseObject);
|
| 93 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
96 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
| 94 |
}
|
97 |
}
|
| 95 |
|
98 |
|
| - |
|
99 |
|
| - |
|
100 |
@RequestMapping(value = ProfitMandiConstants.URL_DEALS, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
| - |
|
101 |
@ApiImplicitParams({
|
| - |
|
102 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
| - |
|
103 |
required = true, dataType = "string", paramType = "header")
|
| - |
|
104 |
})
|
| - |
|
105 |
@ApiOperation(value = "Get online deals")
|
| - |
|
106 |
public ResponseEntity<?> getOnlineDeals(HttpServletRequest request, @RequestParam(value="categoryId") String categoryId,
|
| - |
|
107 |
@RequestParam(value="offset") String offset, @RequestParam(value="limit") String limit, @RequestParam(value="sort", required=false) String sort,
|
| - |
|
108 |
@RequestParam(value="direction", required=false) String direction, @RequestParam(value="filterData", required=false) String filterData ){
|
| - |
|
109 |
logger.info("Request "+request.getParameterMap());
|
| - |
|
110 |
String response = null;
|
| - |
|
111 |
int userId = (int)request.getAttribute("userId");
|
| - |
|
112 |
//TODO: move to properties
|
| - |
|
113 |
String uri = "/deals/"+userId;
|
| - |
|
114 |
RestClient rc = new RestClient(SchemeType.HTTP, host , port);
|
| - |
|
115 |
Map<String, String> params = new HashMap<>();
|
| - |
|
116 |
params.put("offset", offset);
|
| - |
|
117 |
params.put("limit", limit);
|
| - |
|
118 |
params.put("categoryId", categoryId);
|
| - |
|
119 |
params.put("direction", direction);
|
| - |
|
120 |
params.put("sort", sort);
|
| - |
|
121 |
params.put("source", "online");
|
| - |
|
122 |
params.put("filterData", filterData);
|
| - |
|
123 |
List<Object> responseObject = new ArrayList<>();
|
| - |
|
124 |
try {
|
| - |
|
125 |
response = rc.get(uri, params);
|
| - |
|
126 |
} catch (Exception | ProfitMandiBusinessException e) {
|
| - |
|
127 |
logger.error("Unable to get deals",e);
|
| - |
|
128 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, responseObject);
|
| - |
|
129 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
| - |
|
130 |
}
|
| - |
|
131 |
JsonArray result_json = Json.parse(response).asArray();
|
| - |
|
132 |
for (JsonValue j : result_json ){
|
| - |
|
133 |
logger.info("res "+j.asArray());
|
| - |
|
134 |
List<Object> innerObject = new ArrayList<>();
|
| - |
|
135 |
for (JsonValue jsonObject : j.asArray()){
|
| - |
|
136 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
| - |
|
137 |
}
|
| - |
|
138 |
if (innerObject.size() > 0){
|
| - |
|
139 |
responseObject.add(innerObject);
|
| - |
|
140 |
}
|
| - |
|
141 |
}
|
| - |
|
142 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, responseObject);
|
| - |
|
143 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
| - |
|
144 |
}
|
| - |
|
145 |
|
| - |
|
146 |
|
| - |
|
147 |
/* @RequestMapping(value = "/direct-deals", method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
| - |
|
148 |
@ApiImplicitParams({
|
| - |
|
149 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
| - |
|
150 |
required = true, dataType = "string", paramType = "header")
|
| - |
|
151 |
})
|
| - |
|
152 |
public ResponseEntity<?> getDirectDeals(HttpServletRequest request, @RequestParam(value="categoryId") String categoryId,@RequestParam(value="offset") String offset,
|
| - |
|
153 |
@RequestParam(value="limit") String limit, @RequestParam(value="sort", required=false) String sort, @RequestParam(value="direction", required=false) String direction,
|
| - |
|
154 |
@RequestParam(value="filterData", required=false) String filterData ){
|
| - |
|
155 |
|
| - |
|
156 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
| - |
|
157 |
}*/
|
| - |
|
158 |
|
| 96 |
private Object toDealObject(JsonObject jsonObject){
|
159 |
private Object toDealObject(JsonObject jsonObject){
|
| 97 |
if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1){
|
160 |
if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1){
|
| 98 |
return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
|
161 |
return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
|
| 99 |
}
|
162 |
}
|
| 100 |
return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
|
163 |
return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
|