Add role chang status (not finish)
This commit is contained in:
@@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.GetMapping
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
import top.fatweb.api.converter.permission.GroupConverter
|
import top.fatweb.api.converter.permission.GroupConverter
|
||||||
import top.fatweb.api.entity.common.ResponseCode
|
|
||||||
import top.fatweb.api.entity.common.ResponseResult
|
import top.fatweb.api.entity.common.ResponseResult
|
||||||
import top.fatweb.api.param.authentication.GroupGetParam
|
import top.fatweb.api.param.authentication.GroupGetParam
|
||||||
import top.fatweb.api.service.permission.IGroupService
|
import top.fatweb.api.service.permission.IGroupService
|
||||||
@@ -31,8 +30,8 @@ class GroupController(
|
|||||||
@Operation(summary = "获取用户组列表")
|
@Operation(summary = "获取用户组列表")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
fun get(@Valid groupGetParam: GroupGetParam?): ResponseResult<PageVo<GroupVo>> {
|
fun get(@Valid groupGetParam: GroupGetParam?): ResponseResult<PageVo<GroupVo>> {
|
||||||
return ResponseResult.success(
|
return ResponseResult.databaseSuccess(
|
||||||
ResponseCode.DATABASE_SELECT_SUCCESS, data = GroupConverter.groupPageToGroupPageVo(
|
data = GroupConverter.groupPageToGroupPageVo(
|
||||||
groupService.getPage(groupGetParam)
|
groupService.getPage(groupGetParam)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.GetMapping
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
import top.fatweb.api.converter.permission.PowerConverter
|
import top.fatweb.api.converter.permission.PowerConverter
|
||||||
|
import top.fatweb.api.entity.common.ResponseResult
|
||||||
import top.fatweb.api.service.permission.IPowerService
|
import top.fatweb.api.service.permission.IPowerService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,5 +20,5 @@ class PowerController(
|
|||||||
) {
|
) {
|
||||||
@Operation(summary = "获取权限列表")
|
@Operation(summary = "获取权限列表")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
fun get() = PowerConverter.powerSetToPowerSetVo(powerService.getAll())
|
fun get() = ResponseResult.databaseSuccess(data = PowerConverter.powerSetToPowerSetVo(powerService.getAll()))
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ import top.fatweb.api.converter.permission.RoleConverter
|
|||||||
import top.fatweb.api.entity.common.ResponseCode
|
import top.fatweb.api.entity.common.ResponseCode
|
||||||
import top.fatweb.api.entity.common.ResponseResult
|
import top.fatweb.api.entity.common.ResponseResult
|
||||||
import top.fatweb.api.param.authentication.RoleAddParam
|
import top.fatweb.api.param.authentication.RoleAddParam
|
||||||
|
import top.fatweb.api.param.authentication.RoleChangeStatusParam
|
||||||
import top.fatweb.api.param.authentication.RoleGetParam
|
import top.fatweb.api.param.authentication.RoleGetParam
|
||||||
import top.fatweb.api.service.permission.IRoleService
|
import top.fatweb.api.service.permission.IRoleService
|
||||||
import top.fatweb.api.vo.PageVo
|
import top.fatweb.api.vo.PageVo
|
||||||
@@ -29,8 +30,8 @@ class RoleController(
|
|||||||
@Operation(summary = "获取角色列表")
|
@Operation(summary = "获取角色列表")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
fun get(roleGetParam: RoleGetParam?): ResponseResult<PageVo<RoleWithPowerVo>> {
|
fun get(roleGetParam: RoleGetParam?): ResponseResult<PageVo<RoleWithPowerVo>> {
|
||||||
return ResponseResult.success(
|
return ResponseResult.databaseSuccess(
|
||||||
ResponseCode.DATABASE_SELECT_SUCCESS, data = RoleConverter.rolePageToRoleWithPowerPageVo(
|
data = RoleConverter.rolePageToRoleWithPowerPageVo(
|
||||||
roleService.getPage(roleGetParam)
|
roleService.getPage(roleGetParam)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -40,7 +41,22 @@ class RoleController(
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult<RoleVo> {
|
fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult<RoleVo> {
|
||||||
return roleService.add(roleAddParam)
|
return roleService.add(roleAddParam)
|
||||||
?.let { ResponseResult.success(ResponseCode.DATABASE_INSERT_SUCCESS, data = RoleConverter.roleToRoleVo(it)) }
|
?.let {
|
||||||
?: let { ResponseResult.fail(ResponseCode.DATABASE_INSERT_FAILED) }
|
ResponseResult.databaseSuccess(
|
||||||
|
ResponseCode.DATABASE_INSERT_SUCCESS,
|
||||||
|
data = RoleConverter.roleToRoleVo(it)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "修改角色状态")
|
||||||
|
@PatchMapping
|
||||||
|
fun changStatus(@Valid @RequestBody roleChangeStatusParam: RoleChangeStatusParam): ResponseResult<Nothing> {
|
||||||
|
return if (roleService.changeStatus(roleChangeStatusParam)) {
|
||||||
|
ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS)
|
||||||
|
} else {
|
||||||
|
ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,11 +4,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage
|
|||||||
import top.fatweb.api.entity.permission.Power
|
import top.fatweb.api.entity.permission.Power
|
||||||
import top.fatweb.api.entity.permission.Role
|
import top.fatweb.api.entity.permission.Role
|
||||||
import top.fatweb.api.param.authentication.RoleAddParam
|
import top.fatweb.api.param.authentication.RoleAddParam
|
||||||
|
import top.fatweb.api.param.authentication.RoleChangeStatusParam
|
||||||
import top.fatweb.api.vo.PageVo
|
import top.fatweb.api.vo.PageVo
|
||||||
import top.fatweb.api.vo.permission.*
|
import top.fatweb.api.vo.permission.RoleVo
|
||||||
|
import top.fatweb.api.vo.permission.RoleWithPowerVo
|
||||||
|
|
||||||
object RoleConverter {
|
object RoleConverter {
|
||||||
fun roleToRoleVo(role: Role): RoleVo = RoleVo(
|
fun roleToRoleVo(role: Role) = RoleVo(
|
||||||
id = role.id,
|
id = role.id,
|
||||||
name = role.name,
|
name = role.name,
|
||||||
enable = role.enable == 1
|
enable = role.enable == 1
|
||||||
@@ -24,7 +26,7 @@ object RoleConverter {
|
|||||||
operations = role.operations?.map { OperationConverter.operationToOperationVo(it) }
|
operations = role.operations?.map { OperationConverter.operationToOperationVo(it) }
|
||||||
)
|
)
|
||||||
|
|
||||||
fun rolePageToRoleWithPowerPageVo(rolePage: IPage<Role>): PageVo<RoleWithPowerVo> = PageVo(
|
fun rolePageToRoleWithPowerPageVo(rolePage: IPage<Role>) = PageVo(
|
||||||
total = rolePage.total,
|
total = rolePage.total,
|
||||||
pages = rolePage.pages,
|
pages = rolePage.pages,
|
||||||
size = rolePage.size,
|
size = rolePage.size,
|
||||||
@@ -34,9 +36,14 @@ object RoleConverter {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
fun roleAddParamToRole(roleAddParam: RoleAddParam): Role = Role().apply {
|
fun roleAddParamToRole(roleAddParam: RoleAddParam) = Role().apply {
|
||||||
name = roleAddParam.name
|
name = roleAddParam.name
|
||||||
enable = if (roleAddParam.enable == true) 1 else 0
|
enable = if (roleAddParam.enable == true) 1 else 0
|
||||||
powers = roleAddParam.powerIds?.map { Power().apply { id = it } }
|
powers = roleAddParam.powerIds?.map { Power().apply { id = it } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun roleChangeStatusParamToRole(roleChangeStatusParam: RoleChangeStatusParam) = Role().apply {
|
||||||
|
id = roleChangeStatusParam.id
|
||||||
|
enable = if (roleChangeStatusParam.enable) 1 else 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,6 @@ data class GroupGetParam(
|
|||||||
@Schema(description = "查询用户组名称")
|
@Schema(description = "查询用户组名称")
|
||||||
val searchName: String? = null,
|
val searchName: String? = null,
|
||||||
|
|
||||||
@Schema(description = "查询使用正则表达式")
|
@Schema(description = "查询使用正则表达式", allowableValues = ["true", "false"])
|
||||||
val searchRegex: Boolean = false,
|
val searchRegex: Boolean = false,
|
||||||
) : PageSortParam()
|
) : PageSortParam()
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ data class RoleAddParam(
|
|||||||
@field:NotBlank(message = "Name can not be blank")
|
@field:NotBlank(message = "Name can not be blank")
|
||||||
val name: String?,
|
val name: String?,
|
||||||
|
|
||||||
@Schema(description = "启用")
|
@Schema(description = "启用", allowableValues = ["true", "false"])
|
||||||
val enable: Boolean? = true,
|
val enable: Boolean? = true,
|
||||||
|
|
||||||
@Schema(description = "权限 ID 列表")
|
@Schema(description = "权限 ID 列表")
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package top.fatweb.api.param.authentication
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
|
import jakarta.validation.constraints.NotNull
|
||||||
|
import jakarta.validation.constraints.Pattern
|
||||||
|
|
||||||
|
data class RoleChangeStatusParam(
|
||||||
|
@Schema(description = "角色 ID")
|
||||||
|
@field:Pattern(regexp = "^\\d+$", message = "ID must be number")
|
||||||
|
@JsonSerialize(using = ToStringSerializer::class)
|
||||||
|
val id: Long,
|
||||||
|
|
||||||
|
@Schema(description = "启用", allowableValues = ["true", "false"])
|
||||||
|
@field:NotNull
|
||||||
|
val enable: Boolean
|
||||||
|
)
|
||||||
@@ -7,6 +7,6 @@ data class RoleGetParam(
|
|||||||
@Schema(description = "查询角色名称")
|
@Schema(description = "查询角色名称")
|
||||||
val searchName: String? = null,
|
val searchName: String? = null,
|
||||||
|
|
||||||
@Schema(description = "查询使用正则表达式")
|
@Schema(description = "查询使用正则表达式", allowableValues = ["true", "false"])
|
||||||
val searchRegex: Boolean = false,
|
val searchRegex: Boolean = false,
|
||||||
) : PageSortParam()
|
) : PageSortParam()
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService
|
import com.baomidou.mybatisplus.extension.service.IService
|
||||||
import top.fatweb.api.entity.permission.Role
|
import top.fatweb.api.entity.permission.Role
|
||||||
import top.fatweb.api.param.authentication.RoleAddParam
|
import top.fatweb.api.param.authentication.RoleAddParam
|
||||||
|
import top.fatweb.api.param.authentication.RoleChangeStatusParam
|
||||||
import top.fatweb.api.param.authentication.RoleGetParam
|
import top.fatweb.api.param.authentication.RoleGetParam
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,4 +19,6 @@ interface IRoleService : IService<Role> {
|
|||||||
fun getPage(roleGetParam: RoleGetParam?): IPage<Role>
|
fun getPage(roleGetParam: RoleGetParam?): IPage<Role>
|
||||||
|
|
||||||
fun add(roleAddParam: RoleAddParam): Role?
|
fun add(roleAddParam: RoleAddParam): Role?
|
||||||
|
|
||||||
|
fun changeStatus(roleChangeStatusParam: RoleChangeStatusParam): Boolean
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import top.fatweb.api.entity.permission.PowerRole
|
|||||||
import top.fatweb.api.entity.permission.Role
|
import top.fatweb.api.entity.permission.Role
|
||||||
import top.fatweb.api.mapper.permission.RoleMapper
|
import top.fatweb.api.mapper.permission.RoleMapper
|
||||||
import top.fatweb.api.param.authentication.RoleAddParam
|
import top.fatweb.api.param.authentication.RoleAddParam
|
||||||
|
import top.fatweb.api.param.authentication.RoleChangeStatusParam
|
||||||
import top.fatweb.api.param.authentication.RoleGetParam
|
import top.fatweb.api.param.authentication.RoleGetParam
|
||||||
import top.fatweb.api.service.permission.IPowerRoleService
|
import top.fatweb.api.service.permission.IPowerRoleService
|
||||||
import top.fatweb.api.service.permission.IRoleService
|
import top.fatweb.api.service.permission.IRoleService
|
||||||
@@ -59,4 +60,8 @@ class RoleServiceImpl(
|
|||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun changeStatus(roleChangeStatusParam: RoleChangeStatusParam): Boolean {
|
||||||
|
return updateById(RoleConverter.roleChangeStatusParamToRole(roleChangeStatusParam))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user