Subversion Repositories SmartDukaan

Rev

Rev 21358 | Rev 21459 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21358 Rev 21445
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.json.JSONObject;
11
import org.slf4j.Logger;
12
import org.slf4j.Logger;
12
import org.slf4j.LoggerFactory;
13
import org.slf4j.LoggerFactory;
13
import org.springframework.beans.factory.annotation.Value;
14
import org.springframework.beans.factory.annotation.Value;
14
import org.springframework.http.HttpStatus;
15
import org.springframework.http.HttpStatus;
15
import org.springframework.http.MediaType;
16
import org.springframework.http.MediaType;
Line 57... Line 58...
57
	})
58
	})
58
	@ApiOperation(value = "Get deals")
59
	@ApiOperation(value = "Get deals")
59
	public ResponseEntity<?> getDeals(HttpServletRequest request, @PathVariable(value="userId") long userId, @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
	public ResponseEntity<?> getDeals(HttpServletRequest request, @PathVariable(value="userId") long userId, @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
		logger.info("Request "+request.getParameterMap());
61
		logger.info("Request "+request.getParameterMap());
61
		String response = null;
62
		String response = null;
-
 
63
		//move to properties
62
		String uri = "/deals/"+userId;
64
		String uri = "/deals/"+userId;
63
		RestClient rc = new RestClient(SchemeType.HTTP, host , port);
65
		RestClient rc = new RestClient(SchemeType.HTTP, host , port);
64
		Map<String, String> params = new HashMap<>();
66
		Map<String, String> params = new HashMap<>();
65
		params.put("offset", offset);
67
		params.put("offset", offset);
66
		params.put("limit", limit);
68
		params.put("limit", limit);
Line 106... Line 108...
106
	})
108
	})
107
	@ApiOperation(value = "Get brand list and count for category")
109
	@ApiOperation(value = "Get brand list and count for category")
108
	public ResponseEntity<?> getBrands(HttpServletRequest request, @RequestParam(value="category_id") String category_id){
110
	public ResponseEntity<?> getBrands(HttpServletRequest request, @RequestParam(value="category_id") String category_id){
109
		logger.info("Request "+request.getParameterMap());
111
		logger.info("Request "+request.getParameterMap());
110
		String response = null;
112
		String response = null;
-
 
113
		//move to properties
111
		String uri = ProfitMandiConstants.URL_BRANDS;
114
		String uri = ProfitMandiConstants.URL_BRANDS;
112
		RestClient rc = new RestClient(SchemeType.HTTP, host , port);
115
		RestClient rc = new RestClient(SchemeType.HTTP, host , port);
113
		Map<String, String> params = new HashMap<>();
116
		Map<String, String> params = new HashMap<>();
114
		params.put("category_id", category_id);
117
		params.put("category_id", category_id);
115
		List<DealBrands> dealBrandsResponse = null;
118
		List<DealBrands> dealBrandsResponse = null;
Line 123... Line 126...
123
		dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>(){}.getType());
126
		dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>(){}.getType());
124
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, dealBrandsResponse);
127
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, dealBrandsResponse);
125
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
128
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
126
	}
129
	}
127
	
130
	
-
 
131
	@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
-
 
132
	@ApiImplicitParams({
-
 
133
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
-
 
134
				required = true, dataType = "string", paramType = "header")
-
 
135
	})
-
 
136
	@ApiOperation(value = "Get unit deal object")
-
 
137
	public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value="id") long id){
-
 
138
		String response = null;
-
 
139
		//move to properties
-
 
140
		String uri = "getDealById/"+id;
-
 
141
		System.out.println("Unit deal "+uri);
-
 
142
		RestClient rc = new RestClient(SchemeType.HTTP, host , port);
-
 
143
		Map<String, String> params = new HashMap<>();
-
 
144
		DealsResponse dealsResponse = null;
-
 
145
		try {
-
 
146
			response = rc.get(uri, params);
-
 
147
		} catch (Exception | ProfitMandiBusinessException e) {
-
 
148
			logger.error("Unable to get deals",e);
-
 
149
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, dealsResponse);
-
 
150
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
-
 
151
		}
-
 
152
		JsonObject result_json = Json.parse(response).asObject();
-
 
153
		if (!result_json.isEmpty()){
-
 
154
			dealsResponse = new Gson().fromJson(response, DealsResponse.class);
-
 
155
		}
-
 
156
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, dealsResponse);
-
 
157
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
-
 
158
	}
128
 
159
 
129
}
160
}