| 21165 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 21220 |
ashik.ali |
3 |
import javax.servlet.http.HttpServletRequest;
|
|
|
4 |
|
| 21165 |
ashik.ali |
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;
|
| 21165 |
ashik.ali |
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;
|
| 21165 |
ashik.ali |
14 |
|
| 21220 |
ashik.ali |
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.repository.dtr.RoleRepository;
|
| 21220 |
ashik.ali |
20 |
|
| 21248 |
ashik.ali |
21 |
/**
|
|
|
22 |
* @author ashikali
|
|
|
23 |
*
|
|
|
24 |
*/
|
| 21165 |
ashik.ali |
25 |
@Controller
|
| 21702 |
ashik.ali |
26 |
@Transactional
|
| 21165 |
ashik.ali |
27 |
public class RoleController {
|
|
|
28 |
|
| 21448 |
ashik.ali |
29 |
@Autowired
|
|
|
30 |
ResponseSender<?> responseSender;
|
|
|
31 |
|
| 21165 |
ashik.ali |
32 |
private static final Logger LOGGER=LoggerFactory.getLogger(RoleController.class);
|
|
|
33 |
|
| 21278 |
ashik.ali |
34 |
@Autowired
|
|
|
35 |
RoleRepository roleRepository;
|
| 21165 |
ashik.ali |
36 |
|
| 21236 |
ashik.ali |
37 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_ALL,method=RequestMethod.GET)
|
| 21496 |
ashik.ali |
38 |
public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize){
|
| 21220 |
ashik.ali |
39 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 21496 |
ashik.ali |
40 |
return responseSender.ok(roleRepository.selectAll(pageNumber, pageSize));
|
| 21220 |
ashik.ali |
41 |
}
|
|
|
42 |
|
| 21236 |
ashik.ali |
43 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_ID,method=RequestMethod.GET)
|
| 21431 |
ashik.ali |
44 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21220 |
ashik.ali |
45 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
46 |
try {
|
| 21448 |
ashik.ali |
47 |
return responseSender.ok(roleRepository.selectById(id));
|
| 21440 |
ashik.ali |
48 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
49 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
50 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21220 |
ashik.ali |
51 |
}
|
|
|
52 |
}
|
|
|
53 |
|
| 21248 |
ashik.ali |
54 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_TYPE,method=RequestMethod.GET)
|
|
|
55 |
public ResponseEntity<?> getByType(HttpServletRequest request, @RequestParam(name = "type") String typeName){
|
|
|
56 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 21529 |
ashik.ali |
57 |
return responseSender.ok(roleRepository.selectByType(null));
|
| 21248 |
ashik.ali |
58 |
}
|
|
|
59 |
|
|
|
60 |
|
| 21236 |
ashik.ali |
61 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_NAME,method=RequestMethod.GET)
|
| 21220 |
ashik.ali |
62 |
public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
|
|
|
63 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
64 |
try {
|
| 21448 |
ashik.ali |
65 |
return responseSender.ok(roleRepository.selectByName(name));
|
| 21440 |
ashik.ali |
66 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
67 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
68 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21220 |
ashik.ali |
69 |
}
|
|
|
70 |
}
|
|
|
71 |
|
| 21236 |
ashik.ali |
72 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_ID,method=RequestMethod.DELETE)
|
| 21431 |
ashik.ali |
73 |
public ResponseEntity<?> deleteById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21220 |
ashik.ali |
74 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
75 |
try {
|
|
|
76 |
roleRepository.deleteById(id);
|
| 21448 |
ashik.ali |
77 |
return responseSender.ok(ResponseCodeHolder.getMessage("ROL_OK_1001"));
|
| 21440 |
ashik.ali |
78 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
79 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
80 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21220 |
ashik.ali |
81 |
}
|
|
|
82 |
}
|
|
|
83 |
|
| 21165 |
ashik.ali |
84 |
}
|