| 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;
|
- |
|
| 4 |
|
- |
|
| 5 |
import javax.servlet.http.HttpServletRequest;
|
3 |
import javax.servlet.http.HttpServletRequest;
|
| 6 |
|
4 |
|
| 7 |
import org.slf4j.Logger;
|
5 |
import org.slf4j.Logger;
|
| 8 |
import org.slf4j.LoggerFactory;
|
6 |
import org.slf4j.LoggerFactory;
|
| 9 |
import org.springframework.beans.factory.annotation.Autowired;
|
7 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 10 |
import org.springframework.http.HttpStatus;
|
- |
|
| 11 |
import org.springframework.http.ResponseEntity;
|
8 |
import org.springframework.http.ResponseEntity;
|
| 12 |
import org.springframework.stereotype.Controller;
|
9 |
import org.springframework.stereotype.Controller;
|
| 13 |
import org.springframework.web.bind.annotation.RequestMapping;
|
10 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 14 |
import org.springframework.web.bind.annotation.RequestMethod;
|
11 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 15 |
import org.springframework.web.bind.annotation.RequestParam;
|
12 |
import org.springframework.web.bind.annotation.RequestParam;
|
| Line 18... |
Line 15... |
| 18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
15 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 19 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
16 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 20 |
import com.spice.profitmandi.common.util.StringUtils;
|
17 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 21 |
import com.spice.profitmandi.dao.enumuration.RoleType;
|
18 |
import com.spice.profitmandi.dao.enumuration.RoleType;
|
| 22 |
import com.spice.profitmandi.dao.repository.RoleRepository;
|
19 |
import com.spice.profitmandi.dao.repository.RoleRepository;
|
| 23 |
import com.spice.profitmandi.web.model.ProfitMandiResponse;
|
- |
|
| 24 |
import com.spice.profitmandi.web.model.Response;
|
- |
|
| 25 |
import com.spice.profitmandi.web.model.ResponseStatus;
|
20 |
import com.spice.profitmandi.web.util.ResponseSender;
|
| 26 |
|
21 |
|
| 27 |
/**
|
22 |
/**
|
| 28 |
* @author ashikali
|
23 |
* @author ashikali
|
| 29 |
*
|
24 |
*
|
| 30 |
*/
|
25 |
*/
|
| 31 |
@Controller
|
26 |
@Controller
|
| 32 |
public class RoleController {
|
27 |
public class RoleController {
|
| 33 |
|
28 |
|
| - |
|
29 |
@Autowired
|
| - |
|
30 |
ResponseSender<?> responseSender;
|
| - |
|
31 |
|
| 34 |
private static final Logger LOGGER=LoggerFactory.getLogger(RoleController.class);
|
32 |
private static final Logger LOGGER=LoggerFactory.getLogger(RoleController.class);
|
| 35 |
|
33 |
|
| 36 |
@Autowired
|
34 |
@Autowired
|
| 37 |
RoleRepository roleRepository;
|
35 |
RoleRepository roleRepository;
|
| 38 |
|
36 |
|
| 39 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_ALL,method=RequestMethod.GET)
|
37 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_ALL,method=RequestMethod.GET)
|
| 40 |
public ResponseEntity<?> getAll(HttpServletRequest request){
|
38 |
public ResponseEntity<?> getAll(HttpServletRequest request){
|
| 41 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
39 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 42 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, roleRepository.selectAll());
|
- |
|
| 43 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
40 |
return responseSender.ok(roleRepository.selectAll());
|
| 44 |
}
|
41 |
}
|
| 45 |
|
42 |
|
| 46 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_ID,method=RequestMethod.GET)
|
43 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_ID,method=RequestMethod.GET)
|
| 47 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
44 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 48 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
45 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 49 |
try {
|
46 |
try {
|
| 50 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, roleRepository.selectById(id));
|
- |
|
| 51 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
47 |
return responseSender.ok(roleRepository.selectById(id));
|
| 52 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
48 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 53 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
49 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 54 |
final Response response=new Response(profitMandiBusinessException.getRejectedType(), profitMandiBusinessException.getRejectedValue(),profitMandiBusinessException.getCode(), profitMandiBusinessException.getMessage());
|
- |
|
| 55 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
- |
|
| 56 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
50 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 57 |
}
|
51 |
}
|
| 58 |
}
|
52 |
}
|
| 59 |
|
53 |
|
| 60 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_TYPE,method=RequestMethod.GET)
|
54 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_TYPE,method=RequestMethod.GET)
|
| 61 |
public ResponseEntity<?> getByType(HttpServletRequest request, @RequestParam(name = "type") String typeName){
|
55 |
public ResponseEntity<?> getByType(HttpServletRequest request, @RequestParam(name = "type") String typeName){
|
| 62 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
56 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 63 |
try {
|
57 |
try {
|
| 64 |
RoleType roleType = StringUtils.toRoleType(typeName);
|
58 |
RoleType roleType = StringUtils.toRoleType(typeName);
|
| 65 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, roleRepository.selectByType(roleType));
|
- |
|
| 66 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
59 |
return responseSender.ok(roleRepository.selectByType(roleType));
|
| 67 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
60 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 68 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
61 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 69 |
final Response response=new Response(profitMandiBusinessException.getRejectedType(), profitMandiBusinessException.getRejectedValue(),profitMandiBusinessException.getCode(), profitMandiBusinessException.getMessage());
|
- |
|
| 70 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
- |
|
| 71 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
62 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 72 |
}
|
63 |
}
|
| 73 |
}
|
64 |
}
|
| 74 |
|
65 |
|
| 75 |
|
66 |
|
| 76 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_NAME,method=RequestMethod.GET)
|
67 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_NAME,method=RequestMethod.GET)
|
| 77 |
public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
|
68 |
public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
|
| 78 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
69 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 79 |
try {
|
70 |
try {
|
| 80 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, roleRepository.selectByName(name));
|
- |
|
| 81 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
71 |
return responseSender.ok(roleRepository.selectByName(name));
|
| 82 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
72 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 83 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
73 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 84 |
final Response response=new Response(profitMandiBusinessException.getRejectedType(), profitMandiBusinessException.getRejectedValue(),profitMandiBusinessException.getCode(), profitMandiBusinessException.getMessage());
|
- |
|
| 85 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
- |
|
| 86 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
74 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 87 |
}
|
75 |
}
|
| 88 |
}
|
76 |
}
|
| 89 |
|
77 |
|
| 90 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_ID,method=RequestMethod.DELETE)
|
78 |
@RequestMapping(value = ProfitMandiConstants.URL_ROLE_ID,method=RequestMethod.DELETE)
|
| 91 |
public ResponseEntity<?> deleteById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
79 |
public ResponseEntity<?> deleteById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 92 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
80 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 93 |
try {
|
81 |
try {
|
| 94 |
roleRepository.deleteById(id);
|
82 |
roleRepository.deleteById(id);
|
| 95 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
|
- |
|
| 96 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
83 |
return responseSender.ok(ResponseCodeHolder.getMessage("ROL_OK_1001"));
|
| 97 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
84 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 98 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
85 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 99 |
final Response response=new Response(profitMandiBusinessException.getRejectedType(), profitMandiBusinessException.getRejectedValue(),profitMandiBusinessException.getCode(), profitMandiBusinessException.getMessage());
|
- |
|
| 100 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
- |
|
| 101 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
86 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 102 |
}
|
87 |
}
|
| 103 |
}
|
88 |
}
|
| 104 |
|
89 |
|
| 105 |
|
- |
|
| 106 |
}
|
90 |
}
|