Finish role add and edit

This commit is contained in:
2023-11-13 17:52:08 +08:00
parent 7a9cd158de
commit e681d9d7b7
10 changed files with 208 additions and 38 deletions

View File

@@ -4,12 +4,12 @@ import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.validation.Valid
import org.springframework.web.bind.annotation.*
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.param.authentication.RoleUpdateParam
import top.fatweb.api.service.permission.IRoleService
import top.fatweb.api.vo.PageVo
import top.fatweb.api.vo.permission.RoleVo
@@ -31,23 +31,36 @@ class RoleController(
@GetMapping
fun get(roleGetParam: RoleGetParam?): ResponseResult<PageVo<RoleWithPowerVo>> {
return ResponseResult.databaseSuccess(
data = RoleConverter.rolePageToRoleWithPowerPageVo(
roleService.getPage(roleGetParam)
)
data = roleService.getPage(roleGetParam)
)
}
@Operation(summary = "获取单个角色")
@GetMapping("/{id}")
fun getOne(@PathVariable id: Long): ResponseResult<RoleWithPowerVo> {
return ResponseResult.databaseSuccess(
data = roleService.getOne(id)
)
}
@Operation(summary = "添加角色")
@PostMapping
fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult<RoleVo> {
return roleService.add(roleAddParam)
?.let {
ResponseResult.databaseSuccess(
ResponseCode.DATABASE_INSERT_SUCCESS,
data = RoleConverter.roleToRoleVo(it)
)
}
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) }
return roleService.add(roleAddParam)?.let {
ResponseResult.databaseSuccess(
ResponseCode.DATABASE_INSERT_SUCCESS, data = it
)
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) }
}
@Operation(summary = "修改角色")
@PutMapping
fun update(@Valid @RequestBody roleUpdateParam: RoleUpdateParam): ResponseResult<RoleVo> {
return roleService.update(roleUpdateParam)?.let {
ResponseResult.databaseSuccess(
ResponseCode.DATABASE_UPDATE_SUCCESS, data = it
)
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) }
}
@Operation(summary = "修改角色状态")