Subversion Repositories SmartDukaan

Rev

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

Rev 21302 Rev 21309
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.time.LocalDateTime;
3
import java.time.LocalDateTime;
-
 
4
import java.util.Map;
4
 
5
 
5
import javax.servlet.http.HttpServletRequest;
6
import javax.servlet.http.HttpServletRequest;
6
 
7
 
7
import org.slf4j.Logger;
8
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9
import org.slf4j.LoggerFactory;
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.http.HttpStatus;
11
import org.springframework.http.HttpStatus;
11
import org.springframework.http.ResponseEntity;
12
import org.springframework.http.ResponseEntity;
12
import org.springframework.stereotype.Controller;
13
import org.springframework.stereotype.Controller;
-
 
14
import org.springframework.web.bind.annotation.RequestBody;
13
import org.springframework.web.bind.annotation.RequestMapping;
15
import org.springframework.web.bind.annotation.RequestMapping;
14
import org.springframework.web.bind.annotation.RequestMethod;
16
import org.springframework.web.bind.annotation.RequestMethod;
15
import org.springframework.web.bind.annotation.RequestParam;
17
import org.springframework.web.bind.annotation.RequestParam;
16
 
18
 
17
import com.spice.profitmandi.common.ResponseCodeHolder;
19
import com.spice.profitmandi.common.ResponseCodeHolder;
Line 37... Line 39...
37
	
39
	
38
	@ApiImplicitParams({
40
	@ApiImplicitParams({
39
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
41
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
40
				required = true, dataType = "string", paramType = "header")
42
				required = true, dataType = "string", paramType = "header")
41
	})
43
	})
-
 
44
	
42
	@ApiOperation(value = "Create Retailer")
45
	@ApiOperation(value = "Create Retailer")
43
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER, method=RequestMethod.POST)
46
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER, method=RequestMethod.POST)
44
	public ResponseEntity<?> createRetailer(HttpServletRequest request){
47
	public ResponseEntity<?> createRetailer(HttpServletRequest request){
45
		LOGGER.info("requested url : "+request.getRequestURL().toString());
48
		LOGGER.info("requested url : "+request.getRequestURL().toString());
46
		final Retailer retailer = (Retailer)request.getAttribute(ProfitMandiConstants.RETAILER);
49
		final Retailer retailer = (Retailer)request.getAttribute(ProfitMandiConstants.RETAILER);
47
		request.removeAttribute(ProfitMandiConstants.RETAILER);
50
		request.removeAttribute(ProfitMandiConstants.RETAILER);
48
		try {
51
		try {
49
			retailer.setCreateTimestamp(LocalDateTime.now());
52
			retailer.setCreateTimestamp(LocalDateTime.now());
50
			retailer.setUpdateTimestamp(LocalDateTime.now());
53
			retailer.setUpdateTimestamp(LocalDateTime.now());
51
			retailerRepository.persist(retailer);
54
			retailerRepository.persist(retailer);
52
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1000"));
55
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("RTLR_OK_1000"));
53
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
56
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
54
		}catch (ProfitMandiBusinessException pmbe) {
57
		}catch (ProfitMandiBusinessException pmbe) {
55
			LOGGER.error("ProfitMandi error: ", pmbe);
58
			LOGGER.error("ProfitMandi error: ", pmbe);
56
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
59
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
57
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
60
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
Line 76... Line 79...
76
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
79
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
77
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
80
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
78
		}
81
		}
79
	}
82
	}
80
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID, method=RequestMethod.GET)
83
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID, method=RequestMethod.GET)
81
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") String id){
84
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") long id){
82
		LOGGER.info("requested url : "+request.getRequestURL().toString());
85
		LOGGER.info("requested url : "+request.getRequestURL().toString());
83
		try {
86
		try {
84
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, retailerRepository.selectById(id));
87
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, retailerRepository.selectById(id));
85
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
88
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
86
		}catch (ProfitMandiBusinessException pmbe) {
89
		}catch (ProfitMandiBusinessException pmbe) {
Line 115... Line 118...
115
		}
118
		}
116
	}
119
	}
117
		
120
		
118
	
121
	
119
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID,method=RequestMethod.DELETE)
122
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID,method=RequestMethod.DELETE)
120
	public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") String id){
123
	public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") long id){
121
		LOGGER.info("requested url : "+request.getRequestURL().toString());
124
		LOGGER.info("requested url : "+request.getRequestURL().toString());
122
		try {
125
		try {
123
			retailerRepository.deleteById(id);
126
			retailerRepository.deleteById(id);
124
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
127
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
125
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
128
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
Line 135... Line 138...
135
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
138
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
136
		}
139
		}
137
	}
140
	}
138
	
141
	
139
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_REMOVE, method=RequestMethod.DELETE)
142
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_REMOVE, method=RequestMethod.DELETE)
140
	public ResponseEntity<?> removeShop(HttpServletRequest request, @RequestParam(name = "shopId") String shopId, @RequestParam(name = "retailerId") String retailerId){
143
	public ResponseEntity<?> removeShop(HttpServletRequest request, @RequestParam(name = "shopId") long shopId, @RequestParam(name = "retailerId") long retailerId){
141
		LOGGER.info("requested url : "+request.getRequestURL().toString());
144
		LOGGER.info("requested url : "+request.getRequestURL().toString());
142
		try {
145
		try {
143
			retailerRepository.removeShop(shopId, retailerId);
146
			retailerRepository.removeShop(shopId, retailerId);
144
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
147
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
145
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
148
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);