|
@@ -11,7 +11,6 @@ import org.springframework.http.MediaType;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -48,7 +47,8 @@ public class RoleController {
|
|
|
|
|
|
|
|
@ApiOperation("获取角色可访问的资源")
|
|
@ApiOperation("获取角色可访问的资源")
|
|
|
@GetMapping(value = "/menus/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
@GetMapping(value = "/menus/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- public String getRoleMenus(@PathVariable("id") Role role) {
|
|
|
|
|
|
|
+ public String getRoleMenus(@PathVariable("id") int roleId) {
|
|
|
|
|
+ Role role = roleService.getRole(roleId);
|
|
|
List<Menu> allMenus = menuQuery.findAll();
|
|
List<Menu> allMenus = menuQuery.findAll();
|
|
|
allMenus.forEach(menu -> {
|
|
allMenus.forEach(menu -> {
|
|
|
// TODO 序列化时会递归 roles 中的 Role 导致 StackOverflow, 因此在序列化时应该把 Role 的 menus 设置为 null
|
|
// TODO 序列化时会递归 roles 中的 Role 导致 StackOverflow, 因此在序列化时应该把 Role 的 menus 设置为 null
|
|
@@ -67,10 +67,8 @@ public class RoleController {
|
|
|
@ApiOperation("设置角色可访问的资源")
|
|
@ApiOperation("设置角色可访问的资源")
|
|
|
@PostMapping(value = "/menus", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
@PostMapping(value = "/menus", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
public String setRoleMenus(@RequestParam(value = "id") Integer roleId,
|
|
public String setRoleMenus(@RequestParam(value = "id") Integer roleId,
|
|
|
- @RequestParam(value = "menuId", required = false) Set<Menu> menus) {
|
|
|
|
|
- if (menus == null) {
|
|
|
|
|
- menus = Collections.emptySet();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ @RequestParam(value = "menuId") List<Integer> menuIds) {
|
|
|
|
|
+ Set<Menu> menus = menuQuery.getMenus(menuIds);
|
|
|
roleService.setRoleMenus(roleId, menus);
|
|
roleService.setRoleMenus(roleId, menus);
|
|
|
return WebResult.success();
|
|
return WebResult.success();
|
|
|
}
|
|
}
|