cn.herodotus.stirrup.rest.servlet.upms.controller.security.SysRoleController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-module-servlet-upms Show documentation
Show all versions of rest-module-servlet-upms Show documentation
Herodotus 软件生态组件库 UPMS 功能 Servlet 环境 REST 接口模块
The newest version!
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2020-2030 郑庚伟 ZHENGGENGWEI (码匠君), Licensed under the AGPL License
*
* This file is part of Herodotus Stirrup.
*
* Herodotus Stirrup is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Herodotus Stirrup is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package cn.herodotus.stirrup.rest.servlet.upms.controller.security;
import cn.herodotus.stirrup.core.definition.domain.Result;
import cn.herodotus.stirrup.data.crud.service.JpaWriteableService;
import cn.herodotus.stirrup.logic.upms.entity.security.SysRole;
import cn.herodotus.stirrup.logic.upms.service.security.SysRoleService;
import cn.herodotus.stirrup.web.api.servlet.AbstractJpaWriteableController;
import cn.herodotus.stirrup.web.core.annotation.AccessLimited;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* Description: SysRoleController
*
* @author : gengwei.zheng
* @date : 2021/10/11 21:27
*/
@RestController
@RequestMapping("/security/role")
@Tags({
@Tag(name = "用户安全管理接口"),
@Tag(name = "系统角色管理接口")
})
public class SysRoleController extends AbstractJpaWriteableController {
private final SysRoleService sysRoleService;
public SysRoleController(SysRoleService sysRoleService) {
this.sysRoleService = sysRoleService;
}
@Override
public JpaWriteableService getWriteableService() {
return this.sysRoleService;
}
@AccessLimited
@Operation(summary = "根据角色代码查询角色", description = "根据输入的角色代码,查询对应的角色",
responses = {
@ApiResponse(description = "查询到的角色", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SysRole.class))),
@ApiResponse(responseCode = "204", description = "查询成功,未查到数据"),
@ApiResponse(responseCode = "500", description = "查询失败")
}
)
@Parameters({
@Parameter(name = "roleCode", in = ParameterIn.PATH, required = true, description = "角色代码"),
})
@GetMapping("/{roleCode}")
public Result findByRoleCode(@PathVariable("roleCode") String roleCode) {
SysRole sysRole = sysRoleService.findByRoleCode(roleCode);
return result(sysRole);
}
@AccessLimited
@Operation(summary = "获取全部角色", description = "获取全部角色数据列表",
responses = {
@ApiResponse(description = "全部数据列表", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Result.class))),
@ApiResponse(responseCode = "204", description = "查询成功,未查到数据"),
@ApiResponse(responseCode = "500", description = "查询失败")
})
@GetMapping("/list")
public Result> findAll() {
List sysAuthorities = sysRoleService.findAll();
return result(sysAuthorities);
}
@Operation(summary = "给角色赋予权限", description = "为角色赋予权限",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(content = @Content(mediaType = "application/x-www-form-urlencoded")),
responses = {@ApiResponse(description = "已分配权限的角色数据", content = @Content(mediaType = "application/json"))})
@Parameters({
@Parameter(name = "roleId", required = true, description = "角色ID"),
@Parameter(name = "permissions[]", required = true, description = "权限对象组成的数组")
})
@PutMapping
public Result assign(@RequestParam(name = "roleId") String roleId, @RequestParam(name = "permissions[]") String[] permissions) {
SysRole sysRole = sysRoleService.assign(roleId, permissions);
return result(sysRole);
}
}