Subversion Repositories SmartDukaan

Rev

Rev 21740 | Rev 22931 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21429 kshitij.so 1
package com.spice.profitmandi.web.controller;
2
 
3
import java.time.LocalDateTime;
4
 
5
import javax.servlet.http.HttpServletRequest;
6
 
7
import org.json.JSONObject;
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
22173 amit.gupta 10
import org.springframework.beans.factory.annotation.Autowired;
21429 kshitij.so 11
import org.springframework.http.HttpStatus;
12
import org.springframework.http.MediaType;
13
import org.springframework.http.ResponseEntity;
14
import org.springframework.stereotype.Controller;
15
import org.springframework.web.bind.annotation.PathVariable;
16
import org.springframework.web.bind.annotation.RequestMapping;
17
import org.springframework.web.bind.annotation.RequestMethod;
18
 
19
import com.google.gson.Gson;
20
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21740 ashik.ali 21
import com.spice.profitmandi.common.model.ProfitMandiResponse;
22
import com.spice.profitmandi.common.model.ResponseStatus;
21429 kshitij.so 23
import com.spice.profitmandi.dao.model.LimitedMasterDataPojo;
21735 ashik.ali 24
import com.spice.profitmandi.dao.repository.dtr.Mongo;
21429 kshitij.so 25
 
26
import io.swagger.annotations.ApiImplicitParam;
27
import io.swagger.annotations.ApiImplicitParams;
28
import io.swagger.annotations.ApiOperation;
29
 
30
@Controller
31
public class MasterDataController {
32
 
33
	private static final Logger logger=LoggerFactory.getLogger(MasterDataController.class);
34
 
22173 amit.gupta 35
 
21429 kshitij.so 36
 
22173 amit.gupta 37
	@Autowired
38
	Mongo mongoClient;
39
 
40
 
21429 kshitij.so 41
	@RequestMapping(value = ProfitMandiConstants.URL_MASTER_DATA, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
42
	@ApiImplicitParams({
43
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
44
				required = true, dataType = "string", paramType = "header")
45
	})
46
	@ApiOperation(value = "Get limited info of master data for skuBundleId")
47
	public ResponseEntity<?> getMasterDataBySkuBundleId(HttpServletRequest request, @PathVariable(value="id") long skuBundleId){
48
		LimitedMasterDataPojo masterData = null;
49
		try {
22173 amit.gupta 50
			JSONObject jsonObject = mongoClient.getItemsByBundleId(skuBundleId);
21429 kshitij.so 51
			masterData = new Gson().fromJson(jsonObject.toString(), LimitedMasterDataPojo.class);
52
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, masterData);
53
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
54
		} catch (Exception e) {
55
			logger.info("Unable to get skuBundleId "+skuBundleId,e);
56
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, masterData);
57
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
58
		}
59
	}
60
 
61
}