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