1 package org.usermanagement.controller;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.http.HttpStatus;
11 import org.springframework.http.MediaType;
12 import org.springframework.web.bind.annotation.PathVariable;
13 import org.springframework.web.bind.annotation.RequestBody;
14 import org.springframework.web.bind.annotation.RequestMapping;
15 import org.springframework.web.bind.annotation.RequestMethod;
16 import org.springframework.web.bind.annotation.ResponseStatus;
17 import org.springframework.web.bind.annotation.RestController;
23 @RequestMapping(
path =
"/role", produces = MediaType.APPLICATION_JSON_VALUE)
26 private static final Logger LOGGER = LoggerFactory.getLogger(
RoleController.class);
31 @ResponseStatus(HttpStatus.OK)
32 @RequestMapping(method = RequestMethod.POST)
35 LOGGER.info(
"[createRole] (name: " + role.getName() +
")");
36 Role roleResponse = roleService.createRole(role);
40 @ResponseStatus(HttpStatus.OK)
41 @RequestMapping(method = RequestMethod.GET)
42 public List<
Role> getRoles() {
43 LOGGER.info(
"[getRoles]");
44 List<Role> roleResponseList = roleService.getAllRole();
45 return roleResponseList;
48 @ResponseStatus(HttpStatus.OK)
49 @RequestMapping(
value =
"/{role_id}", method = RequestMethod.GET)
50 public
Role getRoleById(@PathVariable("role_id") final Long roleId) {
51 LOGGER.info(
"[getRoleById] (id: " + roleId +
")");
52 Role role = roleService.getRoleById(roleId);
57 @ResponseStatus(HttpStatus.NO_CONTENT)
58 @RequestMapping(
value =
"/{role_id}", method = RequestMethod.DELETE)
60 public void deleteRole(@PathVariable(
"role_id") Long roleId) {
61 LOGGER.info(
"[deleteRoleById] (id: " + roleId +
")");
62 roleService.deleteRoleById(roleId);
66 @ResponseStatus(HttpStatus.OK)
67 @RequestMapping(
value =
"/permission/{permission_id}", method = RequestMethod.GET)
70 LOGGER.info(
"[getRolesByPermissionId] (permissionId: " + permissionId +
")");
71 Permission permission = roleService.getRolesByPermissionId(permissionId);
75 @ResponseStatus(HttpStatus.OK)
76 @RequestMapping(
value =
"/{role_id}", method = RequestMethod.PUT)
79 LOGGER.info(
"[updateRole] (id: " + roleId +
", name: " + role.getName() +
")");
80 Role roleResponse = roleService.updateRole(roleId, role);
84 @ResponseStatus(HttpStatus.OK)
85 @RequestMapping(
value =
"/permission/{permission_id}", method = RequestMethod.PUT)
89 LOGGER.info(
"[assignRoleToPermission] (permissionId: " + permissionId +
")");
90 permission = roleService.assignRoleByPermissionId(permissionId, permission);
Permission assignRolesToPermission(@PathVariable("permission_id") final Long permissionId, @RequestBody Permission permission)
void deleteRole(@PathVariable("role_id") Long roleId)
static final String UM_PERMISSION_VIEW_ROLES
Role createRole(@RequestBody final Role role)
Role updateRole(@PathVariable("role_id") Long roleId, @RequestBody final Role role)
static final String UM_ROLE_EDIT
static final String UM_ROLE_ADD
static final String UM_ROLE_DELETE
Permission getRolesByPermissionId(@PathVariable("permission_id") final Long permissionId)
static final String UM_PERMISSION_ASSIGN_ROLES