Subversion Repositories SmartDukaan

Rev

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

Rev 21440 Rev 21448
Line 6... Line 6...
6
import javax.servlet.http.HttpServletRequest;
6
import javax.servlet.http.HttpServletRequest;
7
 
7
 
8
import org.slf4j.Logger;
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
9
import org.slf4j.LoggerFactory;
10
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.http.HttpStatus;
-
 
12
import org.springframework.http.ResponseEntity;
11
import org.springframework.http.ResponseEntity;
13
import org.springframework.stereotype.Controller;
12
import org.springframework.stereotype.Controller;
14
import org.springframework.web.bind.annotation.RequestMapping;
13
import org.springframework.web.bind.annotation.RequestMapping;
15
import org.springframework.web.bind.annotation.RequestMethod;
14
import org.springframework.web.bind.annotation.RequestMethod;
16
import org.springframework.web.bind.annotation.RequestParam;
15
import org.springframework.web.bind.annotation.RequestParam;
Line 19... Line 18...
19
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
18
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
20
import com.spice.profitmandi.common.model.ProfitMandiConstants;
19
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21
import com.spice.profitmandi.dao.entity.Shop;
20
import com.spice.profitmandi.dao.entity.Shop;
22
import com.spice.profitmandi.dao.repository.RetailerRepository;
21
import com.spice.profitmandi.dao.repository.RetailerRepository;
23
import com.spice.profitmandi.dao.repository.ShopRepository;
22
import com.spice.profitmandi.dao.repository.ShopRepository;
24
import com.spice.profitmandi.web.model.ProfitMandiResponse;
-
 
25
import com.spice.profitmandi.web.model.Response;
-
 
26
import com.spice.profitmandi.web.model.ResponseStatus;
23
import com.spice.profitmandi.web.util.ResponseSender;
27
 
24
 
28
@Controller
25
@Controller
29
public class ShopController {
26
public class ShopController {
30
	
27
	
-
 
28
	@Autowired
-
 
29
	ResponseSender<?> responseSender;
-
 
30
	
-
 
31
	
31
	private static final Logger LOGGER=LoggerFactory.getLogger(ShopController.class);
32
	private static final Logger LOGGER=LoggerFactory.getLogger(ShopController.class);
32
	
33
	
33
	@Autowired
34
	@Autowired
34
	ShopRepository shopRepository;
35
	ShopRepository shopRepository;
35
	
36
	
Line 49... Line 50...
49
			//shop.setRetailer(retailer);
50
			//shop.setRetailer(retailer);
50
			shop.setName(createShopMap.get(ProfitMandiConstants.NAME).toString());
51
			shop.setName(createShopMap.get(ProfitMandiConstants.NAME).toString());
51
			shop.setCreateTimestamp(LocalDateTime.now());
52
			shop.setCreateTimestamp(LocalDateTime.now());
52
			shop.setUpdateTimestamp(LocalDateTime.now());
53
			shop.setUpdateTimestamp(LocalDateTime.now());
53
			shopRepository.persist(shop);
54
			shopRepository.persist(shop);
54
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1000"));
-
 
55
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
55
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1000"));
56
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
56
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
57
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
57
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
58
			final Response response=new Response(profitMandiBusinessException.getRejectedType(), profitMandiBusinessException.getRejectedValue(),profitMandiBusinessException.getCode(), profitMandiBusinessException.getMessage());
-
 
59
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
-
 
60
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
58
			return responseSender.badRequest(profitMandiBusinessException);
61
		}
59
		}
62
	}
60
	}
63
	
61
	
64
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ALL, method=RequestMethod.GET)
62
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ALL, method=RequestMethod.GET)
65
	public ResponseEntity<?> getAll(HttpServletRequest request){
63
	public ResponseEntity<?> getAll(HttpServletRequest request){
66
		LOGGER.info("requested url : "+request.getRequestURL().toString());
64
		LOGGER.info("requested url : "+request.getRequestURL().toString());
67
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, shopRepository.selectAll());
-
 
68
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
65
		return responseSender.ok(shopRepository.selectAll());
69
	}
66
	}
70
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ID, method=RequestMethod.GET)
67
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ID, method=RequestMethod.GET)
71
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
68
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
72
		LOGGER.info("requested url : "+request.getRequestURL().toString());
69
		LOGGER.info("requested url : "+request.getRequestURL().toString());
73
		try {
70
		try {
74
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, shopRepository.selectById(id));
-
 
75
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
71
			return responseSender.ok(shopRepository.selectById(id));
76
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
72
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
77
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
73
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
78
			final Response response=new Response(profitMandiBusinessException.getRejectedType(), profitMandiBusinessException.getRejectedValue(),profitMandiBusinessException.getCode(), profitMandiBusinessException.getMessage());
-
 
79
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
-
 
80
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
74
			return responseSender.badRequest(profitMandiBusinessException);
81
		}
75
		}
82
	}
76
	}
83
	
77
	
84
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP_NAME, method=RequestMethod.GET)
-
 
85
	public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
-
 
86
		LOGGER.info("requested url : "+request.getRequestURL().toString());
-
 
87
		try {
-
 
88
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, shopRepository.selectByName(name));
-
 
89
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
-
 
90
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
91
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
92
			final Response response=new Response(profitMandiBusinessException.getRejectedType(), profitMandiBusinessException.getRejectedValue(),profitMandiBusinessException.getCode(), profitMandiBusinessException.getMessage());
-
 
93
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
-
 
94
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
-
 
95
		}
-
 
96
	}
-
 
97
	
-
 
98
	
-
 
99
	
78
	
100
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ID, method=RequestMethod.DELETE)
79
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ID, method=RequestMethod.DELETE)
101
	public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id){
80
	public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id){
102
		LOGGER.info("requested url : "+request.getRequestURL().toString());
81
		LOGGER.info("requested url : "+request.getRequestURL().toString());
103
		try {
82
		try {
104
			shopRepository.deleteById(id);
83
			shopRepository.deleteById(id);
105
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
-
 
106
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
84
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
107
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
85
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
108
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
86
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
109
			final Response response=new Response(profitMandiBusinessException.getRejectedType(), profitMandiBusinessException.getRejectedValue(),profitMandiBusinessException.getCode(), profitMandiBusinessException.getMessage());
-
 
110
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
-
 
111
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
87
			return responseSender.badRequest(profitMandiBusinessException);
112
		}
88
		}
113
	}
89
	}
114
	
90
	
115
}
91
}