Optimize code
This commit is contained in:
@@ -38,9 +38,7 @@ class GroupController(
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasAnyAuthority('system:group:query:one')")
|
||||
fun getOne(@PathVariable id: Long): ResponseResult<GroupWithRoleVo> =
|
||||
ResponseResult.databaseSuccess(
|
||||
data = groupService.getOne(id)
|
||||
)
|
||||
ResponseResult.databaseSuccess(data = groupService.getOne(id))
|
||||
|
||||
/**
|
||||
* Get group paging information
|
||||
@@ -76,7 +74,7 @@ class GroupController(
|
||||
@PreAuthorize("hasAnyAuthority('system:group:query:list', 'system:user:add:one', 'system:user:modify:one')")
|
||||
fun list(): ResponseResult<List<GroupVo>> =
|
||||
ResponseResult.databaseSuccess(
|
||||
data = groupService.listAll()
|
||||
data = groupService.getList()
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -94,11 +92,9 @@ class GroupController(
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:group:add:one')")
|
||||
fun add(@Valid @RequestBody groupAddParam: GroupAddParam): ResponseResult<GroupVo> =
|
||||
groupService.add(groupAddParam)?.let {
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_INSERT_SUCCESS, data = it
|
||||
)
|
||||
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) }
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_INSERT_SUCCESS, data = groupService.add(groupAddParam)
|
||||
)
|
||||
|
||||
/**
|
||||
* Update group
|
||||
@@ -115,11 +111,9 @@ class GroupController(
|
||||
@PutMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:group:modify:one')")
|
||||
fun update(@Valid @RequestBody groupUpdateParam: GroupUpdateParam): ResponseResult<GroupVo> =
|
||||
groupService.update(groupUpdateParam)?.let {
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_UPDATE_SUCCESS, data = it
|
||||
)
|
||||
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) }
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_UPDATE_SUCCESS, data = groupService.update(groupUpdateParam)
|
||||
)
|
||||
|
||||
/**
|
||||
* Update status of group
|
||||
@@ -134,12 +128,10 @@ class GroupController(
|
||||
@Operation(summary = "修改用户组状态")
|
||||
@PatchMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:group:modify:status')")
|
||||
fun updateStatus(@Valid @RequestBody groupUpdateStatusParam: GroupUpdateStatusParam): ResponseResult<Nothing> =
|
||||
if (groupService.status(groupUpdateStatusParam)) {
|
||||
ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS)
|
||||
} else {
|
||||
ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED)
|
||||
}
|
||||
fun updateStatus(@Valid @RequestBody groupUpdateStatusParam: GroupUpdateStatusParam): ResponseResult<Nothing> {
|
||||
groupService.status(groupUpdateStatusParam)
|
||||
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS)
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete group by ID
|
||||
|
||||
@@ -37,11 +37,8 @@ class RoleController(
|
||||
@Operation(summary = "获取单个角色")
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasAnyAuthority('system:role:query:one')")
|
||||
fun getOne(@PathVariable id: Long): ResponseResult<RoleWithPowerVo> {
|
||||
return ResponseResult.databaseSuccess(
|
||||
data = roleService.getOne(id)
|
||||
)
|
||||
}
|
||||
fun getOne(@PathVariable id: Long): ResponseResult<RoleWithPowerVo> =
|
||||
ResponseResult.databaseSuccess(data = roleService.getOne(id))
|
||||
|
||||
/**
|
||||
* Get role paging information
|
||||
@@ -57,11 +54,10 @@ class RoleController(
|
||||
@Operation(summary = "获取角色")
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:role:query:all')")
|
||||
fun get(roleGetParam: RoleGetParam?): ResponseResult<PageVo<RoleWithPowerVo>> {
|
||||
return ResponseResult.databaseSuccess(
|
||||
fun get(roleGetParam: RoleGetParam?): ResponseResult<PageVo<RoleWithPowerVo>> =
|
||||
ResponseResult.databaseSuccess(
|
||||
data = roleService.getPage(roleGetParam)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get role list
|
||||
@@ -77,7 +73,7 @@ class RoleController(
|
||||
@PreAuthorize("hasAnyAuthority('system:role:query:list', 'system:group:add:one', 'system:group:modify:one', 'system:user:add:one', 'system:user:modify:one')")
|
||||
fun list(): ResponseResult<List<RoleVo>> {
|
||||
return ResponseResult.databaseSuccess(
|
||||
data = roleService.listAll()
|
||||
data = roleService.getList()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -95,13 +91,10 @@ class RoleController(
|
||||
@Operation(summary = "添加角色")
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:role:add:one')")
|
||||
fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult<RoleVo> {
|
||||
return roleService.add(roleAddParam)?.let {
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_INSERT_SUCCESS, data = it
|
||||
)
|
||||
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) }
|
||||
}
|
||||
fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult<RoleVo> =
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_INSERT_SUCCESS, data = roleService.add(roleAddParam)
|
||||
)
|
||||
|
||||
/**
|
||||
* Update role
|
||||
@@ -117,13 +110,10 @@ class RoleController(
|
||||
@Operation(summary = "修改角色")
|
||||
@PutMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:role:modify:one')")
|
||||
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) }
|
||||
}
|
||||
fun update(@Valid @RequestBody roleUpdateParam: RoleUpdateParam): ResponseResult<RoleVo> =
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_UPDATE_SUCCESS, data = roleService.update(roleUpdateParam)
|
||||
)
|
||||
|
||||
/**
|
||||
* Update status of role
|
||||
@@ -139,11 +129,8 @@ class RoleController(
|
||||
@PatchMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:role:modify:status')")
|
||||
fun status(@Valid @RequestBody roleUpdateStatusParam: RoleUpdateStatusParam): ResponseResult<Nothing> {
|
||||
return if (roleService.status(roleUpdateStatusParam)) {
|
||||
ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS)
|
||||
} else {
|
||||
ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED)
|
||||
}
|
||||
roleService.status(roleUpdateStatusParam)
|
||||
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.*
|
||||
import top.fatweb.oxygen.api.annotation.BaseController
|
||||
import top.fatweb.oxygen.api.entity.common.ResponseCode
|
||||
import top.fatweb.oxygen.api.entity.common.ResponseResult
|
||||
import top.fatweb.oxygen.api.exception.NoRecordFoundException
|
||||
import top.fatweb.oxygen.api.param.permission.user.*
|
||||
import top.fatweb.oxygen.api.service.permission.IUserService
|
||||
import top.fatweb.oxygen.api.vo.PageVo
|
||||
@@ -38,9 +37,7 @@ class UserController(
|
||||
@Operation(summary = "获取当前用户信息")
|
||||
@GetMapping("info")
|
||||
fun getInfo(): ResponseResult<UserWithPowerInfoVo> =
|
||||
userService.getInfo()?.let {
|
||||
ResponseResult.databaseSuccess(data = it)
|
||||
} ?: let { ResponseResult.databaseFail() }
|
||||
ResponseResult.databaseSuccess(data = userService.getInfo())
|
||||
|
||||
/**
|
||||
* Get user by ID
|
||||
@@ -56,11 +53,7 @@ class UserController(
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasAnyAuthority('system:user:query:one')")
|
||||
fun getOne(@PathVariable id: Long): ResponseResult<UserWithRoleInfoVo> =
|
||||
userService.getOne(id)?.let {
|
||||
ResponseResult.databaseSuccess(data = it)
|
||||
} ?: let {
|
||||
throw NoRecordFoundException()
|
||||
}
|
||||
ResponseResult.databaseSuccess(data = userService.getOne(id))
|
||||
|
||||
/**
|
||||
* Get user paging information
|
||||
@@ -96,11 +89,9 @@ class UserController(
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:user:add:one')")
|
||||
fun add(@Valid @RequestBody userAddParam: UserAddParam): ResponseResult<UserWithPasswordRoleInfoVo> =
|
||||
userService.add(userAddParam)?.let {
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_INSERT_SUCCESS, data = it
|
||||
)
|
||||
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) }
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_INSERT_SUCCESS, data = userService.add(userAddParam)
|
||||
)
|
||||
|
||||
/**
|
||||
* Update user
|
||||
@@ -117,11 +108,9 @@ class UserController(
|
||||
@PutMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:user:modify:one')")
|
||||
fun update(@Valid @RequestBody userUpdateParam: UserUpdateParam): ResponseResult<UserWithRoleInfoVo> =
|
||||
userService.update(userUpdateParam)?.let {
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_UPDATE_SUCCESS, data = it
|
||||
)
|
||||
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) }
|
||||
ResponseResult.databaseSuccess(
|
||||
ResponseCode.DATABASE_UPDATE_SUCCESS, data = userService.update(userUpdateParam)
|
||||
)
|
||||
|
||||
/**
|
||||
* Update user password
|
||||
|
||||
@@ -18,8 +18,7 @@ class BaseController(
|
||||
@Operation(summary = "获取单个基板")
|
||||
@GetMapping("/{id}")
|
||||
fun getOne(@PathVariable id: Long): ResponseResult<ToolBaseVo> =
|
||||
toolBaseService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) }
|
||||
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
|
||||
ResponseResult.databaseSuccess(data = toolBaseService.getOne(id))
|
||||
|
||||
@Operation(summary = "获取基板")
|
||||
@GetMapping
|
||||
@@ -46,5 +45,5 @@ class BaseController(
|
||||
@DeleteMapping("/{id}")
|
||||
fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
|
||||
if (toolBaseService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED)
|
||||
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)
|
||||
}
|
||||
@@ -25,8 +25,7 @@ class CategoryController(
|
||||
@Operation(summary = "获取单个类别")
|
||||
@GetMapping("/{id}")
|
||||
fun getOne(@PathVariable id: Long): ResponseResult<ToolCategoryVo> =
|
||||
toolCategoryService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) }
|
||||
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
|
||||
ResponseResult.databaseSuccess(data = toolCategoryService.getOne(id))
|
||||
|
||||
@Operation(summary = "获取类别")
|
||||
@GetMapping
|
||||
@@ -53,5 +52,5 @@ class CategoryController(
|
||||
@DeleteMapping("/{id}")
|
||||
fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
|
||||
if (toolCategoryService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED)
|
||||
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)
|
||||
}
|
||||
@@ -24,8 +24,7 @@ class EditController(
|
||||
@Operation(summary = "获取单个工具")
|
||||
@GetMapping("/{id}")
|
||||
fun getOne(@PathVariable id: Long): ResponseResult<ToolVo> =
|
||||
toolService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) }
|
||||
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
|
||||
ResponseResult.databaseSuccess(data = toolService.getOne(id))
|
||||
|
||||
@Operation(summary = "获取工具")
|
||||
@GetMapping
|
||||
@@ -52,5 +51,5 @@ class EditController(
|
||||
@DeleteMapping("/{id}")
|
||||
fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
|
||||
if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED)
|
||||
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)
|
||||
}
|
||||
@@ -18,8 +18,7 @@ class ManagementController(
|
||||
@Operation(summary = "获取单个工具")
|
||||
@GetMapping("/{id}")
|
||||
fun getOne(@PathVariable id: Long): ResponseResult<ToolVo> =
|
||||
toolService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) }
|
||||
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
|
||||
ResponseResult.databaseSuccess(data = toolService.getOne(id))
|
||||
|
||||
@Operation(summary = "获取工具")
|
||||
@GetMapping
|
||||
@@ -46,5 +45,5 @@ class ManagementController(
|
||||
@DeleteMapping("/{id}")
|
||||
fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
|
||||
if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED)
|
||||
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)
|
||||
}
|
||||
@@ -18,8 +18,7 @@ class TemplateController(
|
||||
@Operation(summary = "获取单个模板")
|
||||
@GetMapping("/{id}")
|
||||
fun getOne(@PathVariable id: Long): ResponseResult<ToolTemplateVo> =
|
||||
toolTemplateService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) }
|
||||
?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) }
|
||||
ResponseResult.databaseSuccess(data = toolTemplateService.getOne(id))
|
||||
|
||||
@Operation(summary = "获取模板")
|
||||
@GetMapping
|
||||
@@ -46,5 +45,5 @@ class TemplateController(
|
||||
@DeleteMapping("/{id}")
|
||||
fun delete(@PathVariable id: Long): ResponseResult<Nothing> =
|
||||
if (toolTemplateService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED)
|
||||
else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)
|
||||
}
|
||||
Reference in New Issue
Block a user