Complete core functions #9

Merged
FatttSnake merged 171 commits from FatttSnake into dev 2024-02-23 11:56:35 +08:00
10 changed files with 64 additions and 15 deletions
Showing only changes of commit 7a9cd158de - Show all commits

View File

@@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
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.param.authentication.GroupGetParam
import top.fatweb.api.service.permission.IGroupService
@@ -31,8 +30,8 @@ class GroupController(
@Operation(summary = "获取用户组列表")
@GetMapping
fun get(@Valid groupGetParam: GroupGetParam?): ResponseResult<PageVo<GroupVo>> {
return ResponseResult.success(
ResponseCode.DATABASE_SELECT_SUCCESS, data = GroupConverter.groupPageToGroupPageVo(
return ResponseResult.databaseSuccess(
data = GroupConverter.groupPageToGroupPageVo(
groupService.getPage(groupGetParam)
)
)

View File

@@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import top.fatweb.api.converter.permission.PowerConverter
import top.fatweb.api.entity.common.ResponseResult
import top.fatweb.api.service.permission.IPowerService
/**
@@ -19,5 +20,5 @@ class PowerController(
) {
@Operation(summary = "获取权限列表")
@GetMapping
fun get() = PowerConverter.powerSetToPowerSetVo(powerService.getAll())
fun get() = ResponseResult.databaseSuccess(data = PowerConverter.powerSetToPowerSetVo(powerService.getAll()))
}

View File

@@ -8,6 +8,7 @@ import top.fatweb.api.converter.permission.RoleConverter
import top.fatweb.api.entity.common.ResponseCode
import top.fatweb.api.entity.common.ResponseResult
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.service.permission.IRoleService
import top.fatweb.api.vo.PageVo
@@ -29,8 +30,8 @@ class RoleController(
@Operation(summary = "获取角色列表")
@GetMapping
fun get(roleGetParam: RoleGetParam?): ResponseResult<PageVo<RoleWithPowerVo>> {
return ResponseResult.success(
ResponseCode.DATABASE_SELECT_SUCCESS, data = RoleConverter.rolePageToRoleWithPowerPageVo(
return ResponseResult.databaseSuccess(
data = RoleConverter.rolePageToRoleWithPowerPageVo(
roleService.getPage(roleGetParam)
)
)
@@ -40,7 +41,22 @@ class RoleController(
@PostMapping
fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult<RoleVo> {
return roleService.add(roleAddParam)
?.let { ResponseResult.success(ResponseCode.DATABASE_INSERT_SUCCESS, data = RoleConverter.roleToRoleVo(it)) }
?: let { ResponseResult.fail(ResponseCode.DATABASE_INSERT_FAILED) }
?.let {
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)
}
}
}

View File

@@ -4,11 +4,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage
import top.fatweb.api.entity.permission.Power
import top.fatweb.api.entity.permission.Role
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.permission.*
import top.fatweb.api.vo.permission.RoleVo
import top.fatweb.api.vo.permission.RoleWithPowerVo
object RoleConverter {
fun roleToRoleVo(role: Role): RoleVo = RoleVo(
fun roleToRoleVo(role: Role) = RoleVo(
id = role.id,
name = role.name,
enable = role.enable == 1
@@ -24,7 +26,7 @@ object RoleConverter {
operations = role.operations?.map { OperationConverter.operationToOperationVo(it) }
)
fun rolePageToRoleWithPowerPageVo(rolePage: IPage<Role>): PageVo<RoleWithPowerVo> = PageVo(
fun rolePageToRoleWithPowerPageVo(rolePage: IPage<Role>) = PageVo(
total = rolePage.total,
pages = rolePage.pages,
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
enable = if (roleAddParam.enable == true) 1 else 0
powers = roleAddParam.powerIds?.map { Power().apply { id = it } }
}
fun roleChangeStatusParamToRole(roleChangeStatusParam: RoleChangeStatusParam) = Role().apply {
id = roleChangeStatusParam.id
enable = if (roleChangeStatusParam.enable) 1 else 0
}
}

View File

@@ -7,6 +7,6 @@ data class GroupGetParam(
@Schema(description = "查询用户组名称")
val searchName: String? = null,
@Schema(description = "查询使用正则表达式")
@Schema(description = "查询使用正则表达式", allowableValues = ["true", "false"])
val searchRegex: Boolean = false,
) : PageSortParam()

View File

@@ -8,7 +8,7 @@ data class RoleAddParam(
@field:NotBlank(message = "Name can not be blank")
val name: String?,
@Schema(description = "启用")
@Schema(description = "启用", allowableValues = ["true", "false"])
val enable: Boolean? = true,
@Schema(description = "权限 ID 列表")

View File

@@ -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
)

View File

@@ -7,6 +7,6 @@ data class RoleGetParam(
@Schema(description = "查询角色名称")
val searchName: String? = null,
@Schema(description = "查询使用正则表达式")
@Schema(description = "查询使用正则表达式", allowableValues = ["true", "false"])
val searchRegex: Boolean = false,
) : PageSortParam()

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage
import com.baomidou.mybatisplus.extension.service.IService
import top.fatweb.api.entity.permission.Role
import top.fatweb.api.param.authentication.RoleAddParam
import top.fatweb.api.param.authentication.RoleChangeStatusParam
import top.fatweb.api.param.authentication.RoleGetParam
/**
@@ -18,4 +19,6 @@ interface IRoleService : IService<Role> {
fun getPage(roleGetParam: RoleGetParam?): IPage<Role>
fun add(roleAddParam: RoleAddParam): Role?
fun changeStatus(roleChangeStatusParam: RoleChangeStatusParam): Boolean
}

View File

@@ -10,6 +10,7 @@ import top.fatweb.api.entity.permission.PowerRole
import top.fatweb.api.entity.permission.Role
import top.fatweb.api.mapper.permission.RoleMapper
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.service.permission.IPowerRoleService
import top.fatweb.api.service.permission.IRoleService
@@ -59,4 +60,8 @@ class RoleServiceImpl(
return null
}
override fun changeStatus(roleChangeStatusParam: RoleChangeStatusParam): Boolean {
return updateById(RoleConverter.roleChangeStatusParamToRole(roleChangeStatusParam))
}
}