Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
21220 ashik.ali 1
package com.spice.profitmandi.web.controller;
2
 
3
import javax.servlet.http.HttpServletRequest;
4
 
5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
21278 ashik.ali 7
import org.springframework.beans.factory.annotation.Autowired;
21220 ashik.ali 8
import org.springframework.http.ResponseEntity;
9
import org.springframework.stereotype.Controller;
21702 ashik.ali 10
import org.springframework.transaction.annotation.Transactional;
21220 ashik.ali 11
import org.springframework.web.bind.annotation.RequestMapping;
12
import org.springframework.web.bind.annotation.RequestMethod;
13
import org.springframework.web.bind.annotation.RequestParam;
14
 
15
import com.spice.profitmandi.common.ResponseCodeHolder;
21248 ashik.ali 16
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
21236 ashik.ali 17
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21740 ashik.ali 18
import com.spice.profitmandi.common.web.util.ResponseSender;
21735 ashik.ali 19
import com.spice.profitmandi.dao.entity.dtr.Api;
20
import com.spice.profitmandi.dao.repository.dtr.ApiRepository;
21220 ashik.ali 21
 
22
@Controller
21702 ashik.ali 23
@Transactional
21220 ashik.ali 24
public class ApiController {
25
 
21448 ashik.ali 26
	@Autowired
27
	ResponseSender<?> responseSender;
28
 
21220 ashik.ali 29
	private static final Logger LOGGER=LoggerFactory.getLogger(ApiController.class);
30
 
21278 ashik.ali 31
	@Autowired
32
	ApiRepository apiRepository;
21220 ashik.ali 33
 
21236 ashik.ali 34
	@RequestMapping(value = ProfitMandiConstants.URL_API, method=RequestMethod.POST)
21220 ashik.ali 35
	public ResponseEntity<?> createApi(HttpServletRequest request){
36
		LOGGER.info("requested url : "+request.getRequestURL().toString());
21236 ashik.ali 37
		final Api api = (Api)request.getAttribute(ProfitMandiConstants.API);
38
		request.removeAttribute(ProfitMandiConstants.API);
21220 ashik.ali 39
		try {
40
			apiRepository.persist(api);
21448 ashik.ali 41
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1000"));
21440 ashik.ali 42
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
43
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
21448 ashik.ali 44
			return responseSender.badRequest(profitMandiBusinessException);
21220 ashik.ali 45
		}
46
	}
21278 ashik.ali 47
 
21236 ashik.ali 48
	@RequestMapping(value = ProfitMandiConstants.URL_API_ALL,method=RequestMethod.GET)
21496 ashik.ali 49
	public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize){
21220 ashik.ali 50
		LOGGER.info("requested url : "+request.getRequestURL().toString());
21496 ashik.ali 51
		return responseSender.ok(apiRepository.selectAll(pageNumber, pageSize));
21426 ashik.ali 52
 
21448 ashik.ali 53
 
21220 ashik.ali 54
	}
21236 ashik.ali 55
	@RequestMapping(value = ProfitMandiConstants.URL_API_ID,method=RequestMethod.GET)
21431 ashik.ali 56
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
21220 ashik.ali 57
		LOGGER.info("requested url : "+request.getRequestURL().toString());
58
		try {
21448 ashik.ali 59
			return responseSender.ok(apiRepository.selectById(id));
60
 
21440 ashik.ali 61
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
62
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
21448 ashik.ali 63
			return responseSender.badRequest(profitMandiBusinessException);
21220 ashik.ali 64
		}
65
	}
66
 
21236 ashik.ali 67
	@RequestMapping(value = ProfitMandiConstants.URL_API_NAME,method=RequestMethod.GET)
21220 ashik.ali 68
	public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
69
		LOGGER.info("requested url : "+request.getRequestURL().toString());
70
		try {
21448 ashik.ali 71
			return responseSender.ok(apiRepository.selectByName(name));
72
 
21440 ashik.ali 73
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
74
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
21448 ashik.ali 75
			return responseSender.badRequest(profitMandiBusinessException);
21220 ashik.ali 76
		}
77
	}
78
 
21236 ashik.ali 79
	@RequestMapping(value = ProfitMandiConstants.URL_API_URI,method=RequestMethod.GET)
21220 ashik.ali 80
	public ResponseEntity<?> getByUri(HttpServletRequest request, @RequestParam(name = "uri") String uri){
81
		LOGGER.info("requested url : "+request.getRequestURL().toString());
21448 ashik.ali 82
		return responseSender.ok(apiRepository.selectByUri(uri));
21426 ashik.ali 83
 
21448 ashik.ali 84
 
21220 ashik.ali 85
	}
86
 
21236 ashik.ali 87
	@RequestMapping(value = ProfitMandiConstants.URL_API_ID,method=RequestMethod.DELETE)
21431 ashik.ali 88
	public ResponseEntity<?> deleteById(HttpServletRequest request, @RequestParam(name = "id") int id){
21220 ashik.ali 89
		LOGGER.info("requested url : "+request.getRequestURL().toString());
90
		try {
91
			apiRepository.deleteById(id);
21448 ashik.ali 92
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
21440 ashik.ali 93
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
94
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
21448 ashik.ali 95
			return responseSender.badRequest(profitMandiBusinessException);
21220 ashik.ali 96
		}
97
	}
21236 ashik.ali 98
 
21448 ashik.ali 99
}