Add kdoc
This commit is contained in:
@@ -35,6 +35,7 @@ class DataFormatConfig {
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see TimeZone
|
||||
*/
|
||||
@set:Value("\${spring.jackson.time-zone}}")
|
||||
lateinit var timeZone: TimeZone
|
||||
|
||||
@@ -15,7 +15,6 @@ import top.fatweb.api.properties.ServerProperties
|
||||
*/
|
||||
@Configuration
|
||||
class SwaggerConfig {
|
||||
|
||||
@Bean
|
||||
fun customOpenAPI(): OpenAPI? {
|
||||
val contact = Contact().name("FatttSnake").url("https://fatweb.top").email("fatttsnake@fatweb.top")
|
||||
|
||||
@@ -10,6 +10,7 @@ import top.fatweb.api.interceptor.SysLogInterceptor
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see WebMvcConfigurer
|
||||
*/
|
||||
@Configuration
|
||||
class SysLogConfig(
|
||||
|
||||
@@ -10,6 +10,7 @@ import top.fatweb.api.util.ApiResponseMappingHandlerMapping
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see WebMvcRegistrations
|
||||
*/
|
||||
@Configuration
|
||||
class WebMvcRegistrationsConfig : WebMvcRegistrations {
|
||||
|
||||
@@ -27,10 +27,21 @@ import top.fatweb.api.vo.api.v1.avatar.AvatarBase64Vo
|
||||
class AvatarController(
|
||||
private val avatarService: IAvatarService
|
||||
) {
|
||||
/**
|
||||
* Get random avatar
|
||||
*
|
||||
* @param apiVersion Api version
|
||||
* @param avatarBaseParam Avatar base parameters
|
||||
* @return Avatar byte array
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see AvatarBaseParam
|
||||
* @see ByteArray
|
||||
*/
|
||||
@Operation(summary = "获取随机头像")
|
||||
@GetMapping(produces = [MediaType.IMAGE_PNG_VALUE])
|
||||
fun getDefault(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray {
|
||||
return when ((1..4).random()) {
|
||||
fun getRandom(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray =
|
||||
when ((1..4).random()) {
|
||||
1 -> avatarService.triangle(avatarBaseParam)
|
||||
2 -> avatarService.square(avatarBaseParam)
|
||||
3 -> avatarService.identicon(avatarBaseParam)
|
||||
@@ -43,15 +54,26 @@ class AvatarController(
|
||||
background = avatarBaseParam?.background
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get random avatar as base64
|
||||
*
|
||||
* @param apiVersion Api version
|
||||
* @param avatarBaseParam Avatar base parameters
|
||||
* @return Response object includes avatar base64 string
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see AvatarBaseParam
|
||||
* @see ResponseResult
|
||||
* @see AvatarBase64Vo
|
||||
*/
|
||||
@Operation(summary = "获取随机头像 Base64")
|
||||
@GetMapping("base64")
|
||||
fun getDefaultBase64(
|
||||
fun getRandomBase64(
|
||||
@PathVariable apiVersion: String,
|
||||
@Valid avatarBaseParam: AvatarBaseParam?
|
||||
): ResponseResult<AvatarBase64Vo> {
|
||||
return ResponseResult.success(
|
||||
): ResponseResult<AvatarBase64Vo> =
|
||||
ResponseResult.success(
|
||||
ResponseCode.API_AVATAR_SUCCESS, data = when ((1..4).random()) {
|
||||
1 -> avatarService.triangleBase64(avatarBaseParam)
|
||||
2 -> avatarService.squareBase64(avatarBaseParam)
|
||||
@@ -66,65 +88,160 @@ class AvatarController(
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get triangle avatar
|
||||
*
|
||||
* @param apiVersion Api version
|
||||
* @param avatarBaseParam Avatar base parameters
|
||||
* @return Avatar byte array
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see AvatarBaseParam
|
||||
* @see ByteArray
|
||||
*/
|
||||
@Operation(summary = "三角形头像")
|
||||
@GetMapping("/triangle", produces = [MediaType.IMAGE_PNG_VALUE])
|
||||
fun triangle(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray {
|
||||
return avatarService.triangle(avatarBaseParam)
|
||||
}
|
||||
fun triangle(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray =
|
||||
avatarService.triangle(avatarBaseParam)
|
||||
|
||||
/**
|
||||
* Get triangle avatar as base64
|
||||
*
|
||||
* @param apiVersion Api version
|
||||
* @param avatarBaseParam Avatar base parameters
|
||||
* @return Response object includes avatar base64 string
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see AvatarBaseParam
|
||||
* @see ResponseResult
|
||||
* @see AvatarBase64Vo
|
||||
*/
|
||||
@Operation(summary = "三角形头像 Base64")
|
||||
@GetMapping("/triangle/base64")
|
||||
fun triangleBase64(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ResponseResult<AvatarBase64Vo> {
|
||||
return ResponseResult.success(
|
||||
fun triangleBase64(
|
||||
@PathVariable apiVersion: String,
|
||||
@Valid avatarBaseParam: AvatarBaseParam?
|
||||
): ResponseResult<AvatarBase64Vo> =
|
||||
ResponseResult.success(
|
||||
ResponseCode.API_AVATAR_SUCCESS,
|
||||
data = avatarService.triangleBase64(avatarBaseParam)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get square avatar
|
||||
*
|
||||
* @param apiVersion Api version
|
||||
* @param avatarBaseParam Avatar base parameters
|
||||
* @return Avatar byte array
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see AvatarBaseParam
|
||||
* @see ByteArray
|
||||
*/
|
||||
@Operation(summary = "正方形头像")
|
||||
@GetMapping("/square", produces = [MediaType.IMAGE_PNG_VALUE])
|
||||
fun square(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray {
|
||||
return avatarService.square(avatarBaseParam)
|
||||
}
|
||||
fun square(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray =
|
||||
avatarService.square(avatarBaseParam)
|
||||
|
||||
/**
|
||||
* Get square avatar as base64
|
||||
*
|
||||
* @param apiVersion Api version
|
||||
* @param avatarBaseParam Avatar base parameters
|
||||
* @return Response object includes avatar base64 string
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see AvatarBaseParam
|
||||
* @see ResponseResult
|
||||
* @see AvatarBase64Vo
|
||||
*/
|
||||
@Operation(summary = "正方形头像 Base64")
|
||||
@GetMapping("/square/base64")
|
||||
fun squareBase64(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ResponseResult<AvatarBase64Vo> {
|
||||
return ResponseResult.success(
|
||||
fun squareBase64(
|
||||
@PathVariable apiVersion: String,
|
||||
@Valid avatarBaseParam: AvatarBaseParam?
|
||||
): ResponseResult<AvatarBase64Vo> =
|
||||
ResponseResult.success(
|
||||
ResponseCode.API_AVATAR_SUCCESS,
|
||||
data = avatarService.squareBase64(avatarBaseParam)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get identicon avatar
|
||||
*
|
||||
* @param apiVersion Api version
|
||||
* @param avatarBaseParam Avatar base parameters
|
||||
* @return Avatar byte array
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see AvatarBaseParam
|
||||
* @see ByteArray
|
||||
*/
|
||||
@Operation(summary = "Identicon 头像")
|
||||
@GetMapping("/identicon", produces = [MediaType.IMAGE_PNG_VALUE])
|
||||
fun identicon(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray {
|
||||
return avatarService.identicon(avatarBaseParam)
|
||||
}
|
||||
fun identicon(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray =
|
||||
avatarService.identicon(avatarBaseParam)
|
||||
|
||||
/**
|
||||
* Get identicon avatar as base64
|
||||
*
|
||||
* @param apiVersion Api version
|
||||
* @param avatarBaseParam Avatar base parameters
|
||||
* @return Response object includes avatar base64 string
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see AvatarBaseParam
|
||||
* @see ResponseResult
|
||||
* @see AvatarBase64Vo
|
||||
*/
|
||||
@Operation(summary = "Identicon 头像 Base64")
|
||||
@GetMapping("/identicon/base64")
|
||||
fun identiconBase64(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ResponseResult<AvatarBase64Vo> {
|
||||
return ResponseResult.success(
|
||||
fun identiconBase64(
|
||||
@PathVariable apiVersion: String,
|
||||
@Valid avatarBaseParam: AvatarBaseParam?
|
||||
): ResponseResult<AvatarBase64Vo> =
|
||||
ResponseResult.success(
|
||||
ResponseCode.API_AVATAR_SUCCESS,
|
||||
data = avatarService.identiconBase64(avatarBaseParam)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get GitHub avatar
|
||||
*
|
||||
* @param apiVersion Api version
|
||||
* @param avatarGitHubParam Avatar base parameters
|
||||
* @return Avatar byte array
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see AvatarGitHubParam
|
||||
* @see ByteArray
|
||||
*/
|
||||
@Operation(summary = "GitHub 头像")
|
||||
@GetMapping("/github", produces = [MediaType.IMAGE_PNG_VALUE])
|
||||
fun github(@PathVariable apiVersion: String, @Valid avatarGitHubParam: AvatarGitHubParam?): ByteArray {
|
||||
return avatarService.github(avatarGitHubParam)
|
||||
}
|
||||
fun github(@PathVariable apiVersion: String, @Valid avatarGitHubParam: AvatarGitHubParam?): ByteArray =
|
||||
avatarService.github(avatarGitHubParam)
|
||||
|
||||
/**
|
||||
* Get GitHub avatar as base64
|
||||
*
|
||||
* @param apiVersion Api version
|
||||
* @param avatarGitHubParam Avatar base parameters
|
||||
* @return Response object includes avatar base64 string
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see AvatarGitHubParam
|
||||
* @see ResponseResult
|
||||
* @see AvatarBase64Vo
|
||||
*/
|
||||
@Operation(summary = "GitHub 头像 Base64")
|
||||
@GetMapping("/github/base64")
|
||||
fun githubBase64(@PathVariable apiVersion: String, @Valid avatarGitHubParam: AvatarGitHubParam?): ResponseResult<AvatarBase64Vo> {
|
||||
return ResponseResult.success(
|
||||
fun githubBase64(
|
||||
@PathVariable apiVersion: String,
|
||||
@Valid avatarGitHubParam: AvatarGitHubParam?
|
||||
): ResponseResult<AvatarBase64Vo> =
|
||||
ResponseResult.success(
|
||||
ResponseCode.API_AVATAR_SUCCESS,
|
||||
data = avatarService.githubBase64(avatarGitHubParam)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ import top.fatweb.api.entity.common.ResponseResult
|
||||
import top.fatweb.api.param.permission.LoginParam
|
||||
import top.fatweb.api.service.permission.IAuthenticationService
|
||||
import top.fatweb.api.util.WebUtil
|
||||
import top.fatweb.api.vo.permission.LoginVo
|
||||
import top.fatweb.api.vo.permission.TokenVo
|
||||
|
||||
/**
|
||||
* Authentication controller
|
||||
@@ -26,24 +28,59 @@ import top.fatweb.api.util.WebUtil
|
||||
class AuthenticationController(
|
||||
private val authenticationService: IAuthenticationService
|
||||
) {
|
||||
/**
|
||||
* Login
|
||||
*
|
||||
* @param request
|
||||
* @param loginParam Login parameters
|
||||
* @return Response object includes login result
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see HttpServletRequest
|
||||
* @see LoginParam
|
||||
* @see ResponseResult
|
||||
* @see LoginVo
|
||||
*/
|
||||
@Operation(summary = "登录")
|
||||
@PostMapping("/login")
|
||||
fun login(request: HttpServletRequest, @Valid @RequestBody loginParam: LoginParam) = ResponseResult.success(
|
||||
ResponseCode.PERMISSION_LOGIN_SUCCESS,
|
||||
"Login success",
|
||||
authenticationService.login(request, UserConverter.loginParamToUser(loginParam))
|
||||
)
|
||||
fun login(request: HttpServletRequest, @Valid @RequestBody loginParam: LoginParam): ResponseResult<LoginVo> =
|
||||
ResponseResult.success(
|
||||
ResponseCode.PERMISSION_LOGIN_SUCCESS,
|
||||
"Login success",
|
||||
authenticationService.login(request, UserConverter.loginParamToUser(loginParam))
|
||||
)
|
||||
|
||||
/**
|
||||
* Logout
|
||||
*
|
||||
* @param request
|
||||
* @return Response object includes logout result
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see HttpServletRequest
|
||||
* @see ResponseResult
|
||||
*/
|
||||
@Operation(summary = "登出")
|
||||
@PostMapping("/logout")
|
||||
fun logout(request: HttpServletRequest) = when (authenticationService.logout(WebUtil.getToken(request))) {
|
||||
fun logout(request: HttpServletRequest): ResponseResult<Nothing> = when (authenticationService.logout(WebUtil.getToken(request))) {
|
||||
true -> ResponseResult.success(ResponseCode.PERMISSION_LOGOUT_SUCCESS, "Logout success", null)
|
||||
false -> ResponseResult.fail(ResponseCode.PERMISSION_LOGOUT_FAILED, "Logout failed", null)
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew token
|
||||
*
|
||||
* @param request
|
||||
* @return Response object includes new token
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see HttpServletRequest
|
||||
* @see ResponseResult
|
||||
* @see TokenVo
|
||||
*/
|
||||
@Operation(summary = "更新 Token")
|
||||
@GetMapping("/token")
|
||||
fun renewToken(request: HttpServletRequest) = ResponseResult.success(
|
||||
fun renewToken(request: HttpServletRequest): ResponseResult<TokenVo> = ResponseResult.success(
|
||||
ResponseCode.PERMISSION_TOKEN_RENEW_SUCCESS,
|
||||
"Token renew success",
|
||||
authenticationService.renewToken(WebUtil.getToken(request))
|
||||
|
||||
@@ -10,8 +10,8 @@ import top.fatweb.api.entity.common.ResponseResult
|
||||
import top.fatweb.api.param.permission.group.*
|
||||
import top.fatweb.api.service.permission.IGroupService
|
||||
import top.fatweb.api.vo.PageVo
|
||||
import top.fatweb.api.vo.permission.base.GroupVo
|
||||
import top.fatweb.api.vo.permission.GroupWithRoleVo
|
||||
import top.fatweb.api.vo.permission.base.GroupVo
|
||||
|
||||
/**
|
||||
* Group controller
|
||||
@@ -25,67 +25,133 @@ import top.fatweb.api.vo.permission.GroupWithRoleVo
|
||||
class GroupController(
|
||||
val groupService: IGroupService
|
||||
) {
|
||||
/**
|
||||
* Get group by ID
|
||||
*
|
||||
* @param id Group ID
|
||||
* @return Response object includes group info
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ResponseResult
|
||||
* @see GroupWithRoleVo
|
||||
*/
|
||||
@Operation(summary = "获取单个用户组")
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasAnyAuthority('system:group:query:one')")
|
||||
fun getOne(@PathVariable id: Long): ResponseResult<GroupWithRoleVo> {
|
||||
return ResponseResult.databaseSuccess(
|
||||
fun getOne(@PathVariable id: Long): ResponseResult<GroupWithRoleVo> =
|
||||
ResponseResult.databaseSuccess(
|
||||
data = groupService.getOne(id)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get group paging information
|
||||
*
|
||||
* @param groupGetParam Get group parameters
|
||||
* @return Response object includes group paging information
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see GroupGetParam
|
||||
* @see ResponseResult
|
||||
* @see PageVo
|
||||
* @see GroupWithRoleVo
|
||||
*/
|
||||
@Operation(summary = "获取用户组")
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:group:query:all')")
|
||||
fun get(@Valid groupGetParam: GroupGetParam?): ResponseResult<PageVo<GroupWithRoleVo>> {
|
||||
return ResponseResult.databaseSuccess(
|
||||
fun get(@Valid groupGetParam: GroupGetParam?): ResponseResult<PageVo<GroupWithRoleVo>> =
|
||||
ResponseResult.databaseSuccess(
|
||||
data = groupService.getPage(groupGetParam)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get group list
|
||||
*
|
||||
* @return Response object includes group list
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ResponseResult
|
||||
* @see GroupVo
|
||||
*/
|
||||
@Operation(summary = "获取用户组列表")
|
||||
@GetMapping("/list")
|
||||
@PreAuthorize("hasAnyAuthority('system:group:query:list', 'system:user:add:one', 'system:user:modify:one')")
|
||||
fun list(): ResponseResult<List<GroupVo>> {
|
||||
return ResponseResult.databaseSuccess(
|
||||
fun list(): ResponseResult<List<GroupVo>> =
|
||||
ResponseResult.databaseSuccess(
|
||||
data = groupService.listAll()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add group
|
||||
*
|
||||
* @param groupAddParam Add group parameters
|
||||
* @return Response object includes group information
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see GroupAddParam
|
||||
* @see ResponseResult
|
||||
* @see GroupVo
|
||||
*/
|
||||
@Operation(summary = "添加用户组")
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:group:add:one')")
|
||||
fun add(@Valid @RequestBody groupAddParam: GroupAddParam): ResponseResult<GroupVo> {
|
||||
return groupService.add(groupAddParam)?.let {
|
||||
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) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Update group
|
||||
*
|
||||
* @param groupUpdateParam Update group parameters
|
||||
* @return Response object includes group information
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see GroupUpdateParam
|
||||
* @see ResponseResult
|
||||
* @see GroupVo
|
||||
*/
|
||||
@Operation(summary = "修改用户组")
|
||||
@PutMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:group:modify:one')")
|
||||
fun update(@Valid @RequestBody groupUpdateParam: GroupUpdateParam): ResponseResult<GroupVo> {
|
||||
return groupService.update(groupUpdateParam)?.let {
|
||||
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) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Update status of group
|
||||
*
|
||||
* @param groupUpdateStatusParam Update status of group parameters
|
||||
* @return Response object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see GroupUpdateStatusParam
|
||||
* @see ResponseResult
|
||||
*/
|
||||
@Operation(summary = "修改用户组状态")
|
||||
@PatchMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:group:modify:status')")
|
||||
fun changStatus(@Valid @RequestBody groupChangeStatusParam: GroupChangeStatusParam): ResponseResult<Nothing> {
|
||||
return if (groupService.changeStatus(groupChangeStatusParam)) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "删除角色")
|
||||
/**
|
||||
* Delete group by ID
|
||||
*
|
||||
* @param id Group ID
|
||||
* @return Response object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ResponseResult
|
||||
*/
|
||||
@Operation(summary = "删除用户组")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("hasAnyAuthority('system:group:delete:one')")
|
||||
fun delete(@PathVariable id: Long): ResponseResult<Nothing> {
|
||||
@@ -93,7 +159,17 @@ class GroupController(
|
||||
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
}
|
||||
|
||||
@Operation(summary = "批量删除角色")
|
||||
/**
|
||||
* Delete group by list
|
||||
*
|
||||
* @param groupDeleteParam Delete group parameters
|
||||
* @return Response object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see GroupDeleteParam
|
||||
* @see ResponseResult
|
||||
*/
|
||||
@Operation(summary = "批量删除用户组")
|
||||
@DeleteMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:group:delete:multiple')")
|
||||
fun deleteList(@Valid @RequestBody groupDeleteParam: GroupDeleteParam): ResponseResult<Nothing> {
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import top.fatweb.api.entity.common.ResponseResult
|
||||
import top.fatweb.api.service.permission.IPowerService
|
||||
import top.fatweb.api.vo.permission.PowerSetVo
|
||||
|
||||
/**
|
||||
* Power controller
|
||||
@@ -21,8 +22,16 @@ import top.fatweb.api.service.permission.IPowerService
|
||||
class PowerController(
|
||||
private val powerService: IPowerService
|
||||
) {
|
||||
/**
|
||||
* Get power list
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ResponseResult
|
||||
* @see PowerSetVo
|
||||
*/
|
||||
@Operation(summary = "获取权限列表")
|
||||
@GetMapping("/list")
|
||||
@PreAuthorize("hasAnyAuthority('system:power:query:list', 'system:role:add:one', 'system:role:modify:one')")
|
||||
fun getList() = ResponseResult.databaseSuccess(data = powerService.getList())
|
||||
fun getList(): ResponseResult<PowerSetVo> = ResponseResult.databaseSuccess(data = powerService.getList())
|
||||
}
|
||||
@@ -25,6 +25,16 @@ import top.fatweb.api.vo.permission.base.RoleVo
|
||||
class RoleController(
|
||||
private val roleService: IRoleService
|
||||
) {
|
||||
/**
|
||||
* Get role by ID
|
||||
*
|
||||
* @param id Role ID
|
||||
* @return Response object includes role information
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ResponseResult
|
||||
* @see RoleWithPowerVo
|
||||
*/
|
||||
@Operation(summary = "获取单个角色")
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasAnyAuthority('system:role:query:one')")
|
||||
@@ -34,6 +44,17 @@ class RoleController(
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get role paging information
|
||||
*
|
||||
* @param roleGetParam Get role parameters
|
||||
* @return Response object includes role paging information
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see RoleGetParam
|
||||
* @see ResponseResult
|
||||
* @see RoleWithPowerVo
|
||||
*/
|
||||
@Operation(summary = "获取角色")
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:role:query:all')")
|
||||
@@ -43,6 +64,15 @@ class RoleController(
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get role list
|
||||
*
|
||||
* @return Response object includes role list
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ResponseResult
|
||||
* @see RoleVo
|
||||
*/
|
||||
@Operation(summary = "获取角色列表")
|
||||
@GetMapping("/list")
|
||||
@PreAuthorize("hasAnyAuthority('system:role:query:list', 'system:group:add:one', 'system:group:modify:one', 'system:user:add:one', 'system:user:modify:one')")
|
||||
@@ -52,6 +82,17 @@ class RoleController(
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add role
|
||||
*
|
||||
* @param roleAddParam Add role parameters
|
||||
* @return Response object includes role information
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see RoleAddParam
|
||||
* @see ResponseResult
|
||||
* @see RoleVo
|
||||
*/
|
||||
@Operation(summary = "添加角色")
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:role:add:one')")
|
||||
@@ -63,6 +104,17 @@ class RoleController(
|
||||
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Update role
|
||||
*
|
||||
* @param roleUpdateParam Update role parameters
|
||||
* @return Response object includes role information
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see RoleUpdateParam
|
||||
* @see ResponseResult
|
||||
* @see RoleVo
|
||||
*/
|
||||
@Operation(summary = "修改角色")
|
||||
@PutMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:role:modify:one')")
|
||||
@@ -74,17 +126,36 @@ class RoleController(
|
||||
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Update status of role
|
||||
*
|
||||
* @param roleUpdateStatusParam Update status of role parameters
|
||||
* @return Response object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see RoleUpdateStatusParam
|
||||
* @see ResponseResult
|
||||
*/
|
||||
@Operation(summary = "修改角色状态")
|
||||
@PatchMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:role:modify:status')")
|
||||
fun changStatus(@Valid @RequestBody roleChangeStatusParam: RoleChangeStatusParam): ResponseResult<Nothing> {
|
||||
return if (roleService.changeStatus(roleChangeStatusParam)) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete role by ID
|
||||
*
|
||||
* @param id
|
||||
* @return Response object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ResponseResult
|
||||
*/
|
||||
@Operation(summary = "删除角色")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("hasAnyAuthority('system:role:delete:one')")
|
||||
@@ -93,6 +164,16 @@ class RoleController(
|
||||
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete role by list
|
||||
*
|
||||
* @param roleDeleteParam Delete role parameters
|
||||
* @return Response object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see RoleDeleteParam
|
||||
* @see ResponseResult
|
||||
*/
|
||||
@Operation(summary = "批量删除角色")
|
||||
@DeleteMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:role:delete:multiple')")
|
||||
|
||||
@@ -27,64 +27,130 @@ import top.fatweb.api.vo.permission.UserWithRoleInfoVo
|
||||
class UserController(
|
||||
private val userService: IUserService
|
||||
) {
|
||||
/**
|
||||
* Get current user information
|
||||
*
|
||||
* @return Response object includes user information
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ResponseResult
|
||||
* @see UserWithPowerInfoVo
|
||||
*/
|
||||
@Operation(summary = "获取当前用户信息")
|
||||
@GetMapping("info")
|
||||
fun getInfo(): ResponseResult<UserWithPowerInfoVo> {
|
||||
fun getInfo(): ResponseResult<UserWithPowerInfoVo> =
|
||||
userService.getInfo()?.let {
|
||||
return ResponseResult.databaseSuccess(data = it)
|
||||
} ?: let { return ResponseResult.databaseFail() }
|
||||
}
|
||||
ResponseResult.databaseSuccess(data = it)
|
||||
} ?: let { ResponseResult.databaseFail() }
|
||||
|
||||
/**
|
||||
* Get user by ID
|
||||
*
|
||||
* @param id User ID
|
||||
* @return Response object includes user information
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ResponseResult
|
||||
* @see UserWithRoleInfoVo
|
||||
*/
|
||||
@Operation(summary = "获取单个用户")
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasAnyAuthority('system:user:query:one')")
|
||||
fun getOne(@PathVariable id: Long): ResponseResult<UserWithRoleInfoVo> {
|
||||
return userService.getOne(id)?.let {
|
||||
fun getOne(@PathVariable id: Long): ResponseResult<UserWithRoleInfoVo> =
|
||||
userService.getOne(id)?.let {
|
||||
ResponseResult.databaseSuccess(data = it)
|
||||
} ?: let {
|
||||
throw NoRecordFoundException()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user paging information
|
||||
*
|
||||
* @param userGetParam Get user parameters
|
||||
* @return Response object includes user paging information
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see UserGetParam
|
||||
* @see ResponseResult
|
||||
* @see UserWithRoleInfoVo
|
||||
*/
|
||||
@Operation(summary = "获取用户")
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:user:query:all')")
|
||||
fun get(@Valid userGetParam: UserGetParam?): ResponseResult<PageVo<UserWithRoleInfoVo>> {
|
||||
return ResponseResult.databaseSuccess(
|
||||
fun get(@Valid userGetParam: UserGetParam?): ResponseResult<PageVo<UserWithRoleInfoVo>> =
|
||||
ResponseResult.databaseSuccess(
|
||||
data = userService.getPage(userGetParam)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add user
|
||||
*
|
||||
* @param userAddParam Add user parameters
|
||||
* @return Response object includes user information
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see UserAddParam
|
||||
* @see ResponseResult
|
||||
* @see UserWithPasswordRoleInfoVo
|
||||
*/
|
||||
@Operation(summary = "添加用户")
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:user:add:one')")
|
||||
fun add(@Valid @RequestBody userAddParam: UserAddParam): ResponseResult<UserWithPasswordRoleInfoVo> {
|
||||
return userService.add(userAddParam)?.let {
|
||||
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) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user
|
||||
*
|
||||
* @param userUpdateParam Update user parameters
|
||||
* @return Response object includes user information
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see UserUpdateParam
|
||||
* @see ResponseResult
|
||||
* @see UserWithRoleInfoVo
|
||||
*/
|
||||
@Operation(summary = "修改用户")
|
||||
@PutMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:user:modify:one')")
|
||||
fun update(@Valid @RequestBody userUpdateParam: UserUpdateParam): ResponseResult<UserWithRoleInfoVo> {
|
||||
return userService.update(userUpdateParam)?.let {
|
||||
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) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user password
|
||||
*
|
||||
* @param userUpdatePasswordParam Update user password parameters
|
||||
* @return Response object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see UserUpdatePasswordParam
|
||||
* @see ResponseResult
|
||||
*/
|
||||
@Operation(summary = "修改密码")
|
||||
@PatchMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:user:modify:password')")
|
||||
fun changePassword(@Valid @RequestBody userChangePasswordParam: UserChangePasswordParam): ResponseResult<Nothing> {
|
||||
userService.changePassword(userChangePasswordParam)
|
||||
fun password(@Valid @RequestBody userUpdatePasswordParam: UserUpdatePasswordParam): ResponseResult<Nothing> {
|
||||
userService.password(userUpdatePasswordParam)
|
||||
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS)
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user by ID
|
||||
*
|
||||
* @param id User ID
|
||||
* @return Response object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see ResponseResult
|
||||
*/
|
||||
@Operation(summary = "删除用户")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("hasAnyAuthority('system:user:delete:one')")
|
||||
@@ -93,6 +159,16 @@ class UserController(
|
||||
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user by list
|
||||
*
|
||||
* @param userDeleteParam Delete user parameters
|
||||
* @return Response object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see UserDeleteParam
|
||||
* @see ResponseResult
|
||||
*/
|
||||
@Operation(summary = "批量删除用户")
|
||||
@DeleteMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:user:delete:multiple')")
|
||||
@@ -101,4 +177,3 @@ class UserController(
|
||||
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,17 @@ import top.fatweb.api.vo.system.SysLogVo
|
||||
class SysLogController(
|
||||
private val sysLogService: ISysLogService
|
||||
) {
|
||||
/**
|
||||
* Get system log
|
||||
*
|
||||
* @param sysLogGetParam Get system log parameters
|
||||
* @return Response object includes system log
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see SysLogGetParam
|
||||
* @see ResponseResult
|
||||
* @see SysLogVo
|
||||
*/
|
||||
@Operation(summary = "获取")
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:log:query:all')")
|
||||
|
||||
@@ -10,6 +10,16 @@ import top.fatweb.api.vo.permission.base.FuncVo
|
||||
* @since 1.0.0
|
||||
*/
|
||||
object FuncConverter {
|
||||
/**
|
||||
* Convert Func object into FuncVo object
|
||||
*
|
||||
* @param func Func object
|
||||
* @return FuncVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see Func
|
||||
* @see FuncVo
|
||||
*/
|
||||
fun funcToFuncVo(func: Func) = FuncVo(
|
||||
id = func.id,
|
||||
name = func.name,
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage
|
||||
import top.fatweb.api.entity.permission.Group
|
||||
import top.fatweb.api.entity.permission.Role
|
||||
import top.fatweb.api.param.permission.group.GroupAddParam
|
||||
import top.fatweb.api.param.permission.group.GroupChangeStatusParam
|
||||
import top.fatweb.api.param.permission.group.GroupUpdateStatusParam
|
||||
import top.fatweb.api.param.permission.group.GroupUpdateParam
|
||||
import top.fatweb.api.vo.PageVo
|
||||
import top.fatweb.api.vo.permission.base.GroupVo
|
||||
@@ -17,6 +17,16 @@ import top.fatweb.api.vo.permission.GroupWithRoleVo
|
||||
* @since 1.0.0
|
||||
*/
|
||||
object GroupConverter {
|
||||
/**
|
||||
* Convert Group object into GroupVo object
|
||||
*
|
||||
* @param group Group object
|
||||
* @return GroupVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see Group
|
||||
* @see GroupVo
|
||||
*/
|
||||
fun groupToGroupVo(group: Group) = GroupVo(
|
||||
id = group.id,
|
||||
name = group.name,
|
||||
@@ -25,6 +35,16 @@ object GroupConverter {
|
||||
updateTime = group.updateTime
|
||||
)
|
||||
|
||||
/**
|
||||
* Convert Group object into GroupWithRoleVo object
|
||||
*
|
||||
* @param group Group object
|
||||
* @return GroupWithRoleVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see Group
|
||||
* @see GroupWithRoleVo
|
||||
*/
|
||||
fun groupToGroupWithRoleVo(group: Group) = GroupWithRoleVo(
|
||||
id = group.id,
|
||||
name = group.name,
|
||||
@@ -34,7 +54,19 @@ object GroupConverter {
|
||||
roles = group.roles?.map { RoleConverter.roleToRoleVo(it) }
|
||||
)
|
||||
|
||||
fun groupPageToGroupWithRolePageVo(groupPage: IPage<Group>): PageVo<GroupWithRoleVo> = PageVo(
|
||||
/**
|
||||
* Convert IPage<Group> object into PageVo<GroupWithRoleVo> object
|
||||
*
|
||||
* @param groupPage IPage<Group> object
|
||||
* @return PageVo<GroupWithRoleVo> object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see IPage
|
||||
* @see Group
|
||||
* @see PageVo
|
||||
* @see GroupWithRoleVo
|
||||
*/
|
||||
fun groupPageToGroupWithRolePageVo(groupPage: IPage<Group>) = PageVo(
|
||||
total = groupPage.total,
|
||||
pages = groupPage.pages,
|
||||
size = groupPage.size,
|
||||
@@ -44,21 +76,51 @@ object GroupConverter {
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Convert GroupAddParam object into Group object
|
||||
*
|
||||
* @param groupAddParam GroupAddParam object
|
||||
* @return Group object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see GroupAddParam
|
||||
* @see Group
|
||||
*/
|
||||
fun groupAddParamToGroup(groupAddParam: GroupAddParam) = Group().apply {
|
||||
name = groupAddParam.name
|
||||
enable = if (groupAddParam.enable) 1 else 0
|
||||
roles = groupAddParam.roleIds?.map { Role().apply { id = it } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert GroupUpdateParam object into Group object
|
||||
*
|
||||
* @param groupUpdateParam GroupUpdateParam object
|
||||
* @return Group object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see GroupUpdateParam
|
||||
* @see Group
|
||||
*/
|
||||
fun groupUpdateParamToGroup(groupUpdateParam: GroupUpdateParam) = Group().apply {
|
||||
id = groupUpdateParam.id
|
||||
name = groupUpdateParam.name
|
||||
enable = if (groupUpdateParam.enable == true) 1 else 0
|
||||
enable = if (groupUpdateParam.enable) 1 else 0
|
||||
roles = groupUpdateParam.roleIds?.map { Role().apply { id = it } }
|
||||
}
|
||||
|
||||
fun groupChangeStatusParamToGroup(groupChangeStatusParam: GroupChangeStatusParam) = Group().apply {
|
||||
id = groupChangeStatusParam.id
|
||||
enable = if (groupChangeStatusParam.enable) 1 else 0
|
||||
/**
|
||||
* Convert GroupUpdateStatusParam object into Group object
|
||||
*
|
||||
* @param groupUpdateStatusParam GroupUpdateStatusParam object
|
||||
* @return Group object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see GroupUpdateStatusParam
|
||||
* @see Group
|
||||
*/
|
||||
fun groupUpdateStatusParamToGroup(groupUpdateStatusParam: GroupUpdateStatusParam) = Group().apply {
|
||||
id = groupUpdateStatusParam.id
|
||||
enable = if (groupUpdateStatusParam.enable) 1 else 0
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,16 @@ import top.fatweb.api.vo.permission.base.MenuVo
|
||||
* @since 1.0.0
|
||||
*/
|
||||
object MenuConverter {
|
||||
/**
|
||||
* Convert Menu object into MenuVo object
|
||||
*
|
||||
* @param menu Menu object
|
||||
* @return MenuVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see Menu
|
||||
* @see MenuVo
|
||||
*/
|
||||
fun menuToMenuVo(menu: Menu) = MenuVo(
|
||||
id = menu.id,
|
||||
name = menu.name,
|
||||
|
||||
@@ -10,6 +10,16 @@ import top.fatweb.api.vo.permission.base.ModuleVo
|
||||
* @since 1.0.0
|
||||
*/
|
||||
object ModuleConverter {
|
||||
/**
|
||||
* Convert Module object into ModuleVo object
|
||||
*
|
||||
* @param module Module object
|
||||
* @return ModuleVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see Module
|
||||
* @see ModuleVo
|
||||
*/
|
||||
fun moduleToModuleVo(module: Module) = ModuleVo(
|
||||
id = module.id,
|
||||
name = module.name
|
||||
|
||||
@@ -10,6 +10,16 @@ import top.fatweb.api.vo.permission.base.OperationVo
|
||||
* @since 1.0.0
|
||||
*/
|
||||
object OperationConverter {
|
||||
/**
|
||||
* Convert Operation object into OperationVo object
|
||||
*
|
||||
* @param operation Operation object
|
||||
* @return OperationVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see Operation
|
||||
* @see OperationVo
|
||||
*/
|
||||
fun operationToOperationVo(operation: Operation) = OperationVo(
|
||||
id = operation.id,
|
||||
name = operation.name,
|
||||
|
||||
@@ -10,6 +10,16 @@ import top.fatweb.api.vo.permission.PowerSetVo
|
||||
* @since 1.0.0
|
||||
*/
|
||||
object PowerConverter {
|
||||
/**
|
||||
* Convert PowerSet object into PowerSetVo object
|
||||
*
|
||||
* @param powerSet PowerSet object
|
||||
* @return PowerSetVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see PowerSet
|
||||
* @see PowerSetVo
|
||||
*/
|
||||
fun powerSetToPowerSetVo(powerSet: PowerSet) = PowerSetVo(
|
||||
moduleList = powerSet.moduleList?.map { ModuleConverter.moduleToModuleVo(it) },
|
||||
menuList = powerSet.menuList?.map { MenuConverter.menuToMenuVo(it) },
|
||||
|
||||
@@ -4,7 +4,7 @@ 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.permission.role.RoleAddParam
|
||||
import top.fatweb.api.param.permission.role.RoleChangeStatusParam
|
||||
import top.fatweb.api.param.permission.role.RoleUpdateStatusParam
|
||||
import top.fatweb.api.param.permission.role.RoleUpdateParam
|
||||
import top.fatweb.api.vo.PageVo
|
||||
import top.fatweb.api.vo.permission.base.RoleVo
|
||||
@@ -17,6 +17,16 @@ import top.fatweb.api.vo.permission.RoleWithPowerVo
|
||||
* @since 1.0.0
|
||||
*/
|
||||
object RoleConverter {
|
||||
/**
|
||||
* Convert Role object into RoleVo object
|
||||
*
|
||||
* @param role Role object
|
||||
* @return RoleVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see Role
|
||||
* @see RoleVo
|
||||
*/
|
||||
fun roleToRoleVo(role: Role) = RoleVo(
|
||||
id = role.id,
|
||||
name = role.name,
|
||||
@@ -25,6 +35,16 @@ object RoleConverter {
|
||||
updateTime = role.updateTime
|
||||
)
|
||||
|
||||
/**
|
||||
* Convert Role object into RoleWithPowerVo object
|
||||
*
|
||||
* @param role Role object
|
||||
* @return RoleWithPowerVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see Role
|
||||
* @see RoleWithPowerVo
|
||||
*/
|
||||
fun roleToRoleWithPowerVo(role: Role) = RoleWithPowerVo(
|
||||
id = role.id,
|
||||
name = role.name,
|
||||
@@ -37,6 +57,18 @@ object RoleConverter {
|
||||
operations = role.operations?.map { OperationConverter.operationToOperationVo(it) }
|
||||
)
|
||||
|
||||
/**
|
||||
* Convert IPage<Role> object into PageVo object
|
||||
*
|
||||
* @param rolePage IPage<Role> object
|
||||
* @return PageVo<RoleWithPowerVo> object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see IPage
|
||||
* @see Role
|
||||
* @see PageVo
|
||||
* @see RoleWithPowerVo
|
||||
*/
|
||||
fun rolePageToRoleWithPowerPageVo(rolePage: IPage<Role>) = PageVo(
|
||||
total = rolePage.total,
|
||||
pages = rolePage.pages,
|
||||
@@ -47,21 +79,51 @@ object RoleConverter {
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Convert RoleAddParam object into Role object
|
||||
*
|
||||
* @param roleAddParam RoleAddParam object
|
||||
* @return Role object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see RoleAddParam
|
||||
* @see Role
|
||||
*/
|
||||
fun roleAddParamToRole(roleAddParam: RoleAddParam) = Role().apply {
|
||||
name = roleAddParam.name
|
||||
enable = if (roleAddParam.enable == true) 1 else 0
|
||||
enable = if (roleAddParam.enable) 1 else 0
|
||||
powers = roleAddParam.powerIds?.map { Power().apply { id = it } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert RoleUpdateParam into Role object
|
||||
*
|
||||
* @param roleUpdateParam RoleUpdateParam object
|
||||
* @return Role object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see RoleUpdateParam
|
||||
* @see Role
|
||||
*/
|
||||
fun roleUpdateParamToRole(roleUpdateParam: RoleUpdateParam) = Role().apply {
|
||||
id = roleUpdateParam.id
|
||||
name = roleUpdateParam.name
|
||||
enable = if (roleUpdateParam.enable == true) 1 else 0
|
||||
enable = if (roleUpdateParam.enable) 1 else 0
|
||||
powers = roleUpdateParam.powerIds?.map { Power().apply { id = it } }
|
||||
}
|
||||
|
||||
fun roleChangeStatusParamToRole(roleChangeStatusParam: RoleChangeStatusParam) = Role().apply {
|
||||
id = roleChangeStatusParam.id
|
||||
enable = if (roleChangeStatusParam.enable) 1 else 0
|
||||
/**
|
||||
* Convert RoleUpdateStatusParam object into Role object
|
||||
*
|
||||
* @param roleUpdateStatusParam RoleUpdateStatusParam object
|
||||
* @return Role object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see RoleUpdateStatusParam
|
||||
* @see Role
|
||||
*/
|
||||
fun roleUpdateStatusParamToRole(roleUpdateStatusParam: RoleUpdateStatusParam) = Role().apply {
|
||||
id = roleUpdateStatusParam.id
|
||||
enable = if (roleUpdateStatusParam.enable) 1 else 0
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,31 @@ import top.fatweb.avatargenerator.GitHubAvatar
|
||||
* @since 1.0.0
|
||||
*/
|
||||
object UserConverter {
|
||||
|
||||
/**
|
||||
* Convert LoginParam object into User object
|
||||
*
|
||||
* @param loginParam LoginParam object
|
||||
* @return User object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see LoginParam
|
||||
* @see User
|
||||
*/
|
||||
fun loginParamToUser(loginParam: LoginParam) = User().apply {
|
||||
username = loginParam.username
|
||||
password = loginParam.password
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert User object into UserWithPowerInfoVo object
|
||||
*
|
||||
* @param user User object
|
||||
* @return UserWithPowerInfoVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see User
|
||||
* @see UserWithPowerInfoVo
|
||||
*/
|
||||
fun userToUserWithPowerInfoVo(user: User) = UserWithPowerInfoVo(
|
||||
id = user.id,
|
||||
username = user.username,
|
||||
@@ -58,6 +77,16 @@ object UserConverter {
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Convert User object into UserWithRoleInfoVo object
|
||||
*
|
||||
* @param user User object
|
||||
* @return UserWithRoleInfoVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see User
|
||||
* @see UserWithRoleInfoVo
|
||||
*/
|
||||
fun userToUserWithRoleInfoVo(user: User) = UserWithRoleInfoVo(
|
||||
id = user.id,
|
||||
username = user.username,
|
||||
@@ -82,6 +111,16 @@ object UserConverter {
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Convert User object into UserWithInfoVo object
|
||||
*
|
||||
* @param user User object
|
||||
* @return UserWithInfoVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see User
|
||||
* @see UserWithInfoVo
|
||||
*/
|
||||
fun userToUserWithInfoVo(user: User) = UserWithInfoVo(
|
||||
id = user.id,
|
||||
username = user.username,
|
||||
@@ -100,6 +139,16 @@ object UserConverter {
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Convert User object into UserWithPasswordRoleInfoVo object
|
||||
*
|
||||
* @param user User object
|
||||
* @return UserWithPasswordRoleInfoVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see User
|
||||
* @see UserWithPasswordRoleInfoVo
|
||||
*/
|
||||
fun userToUserWithPasswordRoleInfoVo(user: User) = UserWithPasswordRoleInfoVo(
|
||||
id = user.id,
|
||||
username = user.username,
|
||||
@@ -125,6 +174,16 @@ object UserConverter {
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Convert UserAddParam object into User object
|
||||
*
|
||||
* @param userAddParam UserAddParam object
|
||||
* @return User object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see UserAddParam
|
||||
* @see User
|
||||
*/
|
||||
fun userAddParamToUser(userAddParam: UserAddParam) = User().apply {
|
||||
username = userAddParam.username
|
||||
password = userAddParam.password
|
||||
@@ -142,6 +201,16 @@ object UserConverter {
|
||||
groups = userAddParam.groupIds?.map { Group().apply { id = it } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert UserUpdateParam object into User object
|
||||
*
|
||||
* @param userUpdateParam UserUpdateParam object
|
||||
* @return User object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see UserUpdateParam
|
||||
* @see User
|
||||
*/
|
||||
fun userUpdateParamToUser(userUpdateParam: UserUpdateParam) = User().apply {
|
||||
id = userUpdateParam.id
|
||||
username = userUpdateParam.username
|
||||
@@ -158,6 +227,18 @@ object UserConverter {
|
||||
groups = if (userUpdateParam.id != 0L) userUpdateParam.groupIds?.map { Group().apply { id = it } } else null
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert IPage<User> object into PageVo<UserWithRoleInfoVo> object
|
||||
*
|
||||
* @param userPage IPage<User> object
|
||||
* @return PageVo<UserWithRoleInfoVo> object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see IPage
|
||||
* @see User
|
||||
* @see PageVo
|
||||
* @see UserWithRoleInfoVo
|
||||
*/
|
||||
fun userPageToUserWithRoleInfoPageVo(userPage: IPage<User>) = PageVo(
|
||||
total = userPage.total,
|
||||
pages = userPage.pages,
|
||||
|
||||
@@ -10,6 +10,16 @@ import top.fatweb.api.vo.permission.base.UserInfoVo
|
||||
* @since 1.0.0
|
||||
*/
|
||||
object UserInfoConverter {
|
||||
/**
|
||||
* Convert UserInfo object into UserInfoVo object
|
||||
*
|
||||
* @param userInfo UserInfo object
|
||||
* @return UserInfoVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see UserInfo
|
||||
* @see UserInfoVo
|
||||
*/
|
||||
fun userInfoToUserInfoVo(userInfo: UserInfo) = UserInfoVo(
|
||||
id = userInfo.id,
|
||||
userId = userInfo.userId,
|
||||
|
||||
@@ -12,7 +12,19 @@ import top.fatweb.api.vo.system.SysLogVo
|
||||
* @since 1.0.0
|
||||
*/
|
||||
object SysLogConverter {
|
||||
fun sysLogPageToSysLogPageVo(syslogPage: IPage<SysLog>): PageVo<SysLogVo> = PageVo(
|
||||
/**
|
||||
* Convert IPage<SysLog> object into PageVo<SysLogVo> object
|
||||
*
|
||||
* @param syslogPage IPage<Syslog> object
|
||||
* @return PageVo<SysLogVo> object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see IPage
|
||||
* @see SysLog
|
||||
* @see PageVo
|
||||
* @see SysLogVo
|
||||
*/
|
||||
fun sysLogPageToSysLogPageVo(syslogPage: IPage<SysLog>) = PageVo(
|
||||
syslogPage.total,
|
||||
syslogPage.pages,
|
||||
syslogPage.size,
|
||||
|
||||
@@ -10,7 +10,7 @@ import jakarta.validation.constraints.NotNull
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Schema(description = "用户组更改状态请求参数")
|
||||
data class GroupChangeStatusParam(
|
||||
data class GroupUpdateStatusParam(
|
||||
@Schema(description = "用户组 ID")
|
||||
@field:NotNull(message = "ID can not be null")
|
||||
val id: Long?,
|
||||
@@ -10,7 +10,7 @@ import jakarta.validation.constraints.NotNull
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Schema(description = "角色更改状态请求参数")
|
||||
data class RoleChangeStatusParam(
|
||||
data class RoleUpdateStatusParam(
|
||||
@Schema(description = "角色 ID")
|
||||
@field:NotNull(message = "Role id can not be null")
|
||||
val id: Long?,
|
||||
@@ -6,7 +6,7 @@ import jakarta.validation.constraints.NotNull
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Schema(description = "用户更改密码请求参数")
|
||||
data class UserChangePasswordParam(
|
||||
data class UserUpdatePasswordParam(
|
||||
@Schema(description = "用户 ID")
|
||||
@field:NotNull(message = "ID can not be null")
|
||||
val id: Long?,
|
||||
@@ -24,7 +24,7 @@ interface IGroupService : IService<Group> {
|
||||
|
||||
fun update(groupUpdateParam: GroupUpdateParam): GroupVo?
|
||||
|
||||
fun changeStatus(groupChangeStatusParam: GroupChangeStatusParam): Boolean
|
||||
fun status(groupUpdateStatusParam: GroupUpdateStatusParam): Boolean
|
||||
|
||||
fun deleteOne(id: Long)
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ interface IRoleService : IService<Role> {
|
||||
|
||||
fun update(roleUpdateParam: RoleUpdateParam): RoleVo?
|
||||
|
||||
fun changeStatus(roleChangeStatusParam: RoleChangeStatusParam): Boolean
|
||||
fun status(roleUpdateStatusParam: RoleUpdateStatusParam): Boolean
|
||||
|
||||
fun deleteOne(id: Long)
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ interface IUserService : IService<User> {
|
||||
|
||||
fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo?
|
||||
|
||||
fun changePassword(userChangePasswordParam: UserChangePasswordParam)
|
||||
fun password(userUpdatePasswordParam: UserUpdatePasswordParam)
|
||||
|
||||
fun deleteOne(id: Long)
|
||||
|
||||
|
||||
@@ -117,10 +117,10 @@ class GroupServiceImpl(
|
||||
return GroupConverter.groupToGroupVo(group)
|
||||
}
|
||||
|
||||
override fun changeStatus(groupChangeStatusParam: GroupChangeStatusParam): Boolean {
|
||||
updateById(GroupConverter.groupChangeStatusParamToGroup(groupChangeStatusParam)).let {
|
||||
if (it && !groupChangeStatusParam.enable) {
|
||||
groupChangeStatusParam.id?.let { id -> offlineUser(id) }
|
||||
override fun status(groupUpdateStatusParam: GroupUpdateStatusParam): Boolean {
|
||||
updateById(GroupConverter.groupUpdateStatusParamToGroup(groupUpdateStatusParam)).let {
|
||||
if (it && !groupUpdateStatusParam.enable) {
|
||||
groupUpdateStatusParam.id?.let { id -> offlineUser(id) }
|
||||
}
|
||||
|
||||
return it
|
||||
|
||||
@@ -124,10 +124,10 @@ class RoleServiceImpl(
|
||||
return RoleConverter.roleToRoleVo(role)
|
||||
}
|
||||
|
||||
override fun changeStatus(roleChangeStatusParam: RoleChangeStatusParam): Boolean {
|
||||
updateById(RoleConverter.roleChangeStatusParamToRole(roleChangeStatusParam)).let {
|
||||
if (it && !roleChangeStatusParam.enable) {
|
||||
roleChangeStatusParam.id?.let { id -> offlineUser(id) }
|
||||
override fun status(roleUpdateStatusParam: RoleUpdateStatusParam): Boolean {
|
||||
updateById(RoleConverter.roleUpdateStatusParamToRole(roleUpdateStatusParam)).let {
|
||||
if (it && !roleUpdateStatusParam.enable) {
|
||||
roleUpdateStatusParam.id?.let { id -> offlineUser(id) }
|
||||
}
|
||||
|
||||
return it
|
||||
|
||||
@@ -201,25 +201,25 @@ class UserServiceImpl(
|
||||
return UserConverter.userToUserWithRoleInfoVo(user)
|
||||
}
|
||||
|
||||
override fun changePassword(userChangePasswordParam: UserChangePasswordParam) {
|
||||
if (WebUtil.getLoginUserId() != 0L && userChangePasswordParam.id == 0L) {
|
||||
override fun password(userUpdatePasswordParam: UserUpdatePasswordParam) {
|
||||
if (WebUtil.getLoginUserId() != 0L && userUpdatePasswordParam.id == 0L) {
|
||||
throw AccessDeniedException("Access denied")
|
||||
}
|
||||
|
||||
val user = baseMapper.selectById(userChangePasswordParam.id)
|
||||
val user = baseMapper.selectById(userUpdatePasswordParam.id)
|
||||
user?.let {
|
||||
val wrapper = KtUpdateWrapper(User())
|
||||
wrapper.eq(User::id, user.id)
|
||||
.set(User::password, passwordEncoder.encode(userChangePasswordParam.password))
|
||||
.set(User::password, passwordEncoder.encode(userUpdatePasswordParam.password))
|
||||
.set(
|
||||
User::credentialsExpiration,
|
||||
if (user.id != 0L) userChangePasswordParam.credentialsExpiration else null
|
||||
if (user.id != 0L) userUpdatePasswordParam.credentialsExpiration else null
|
||||
)
|
||||
.set(User::updateTime, LocalDateTime.now(ZoneOffset.UTC))
|
||||
|
||||
this.update(wrapper)
|
||||
|
||||
userChangePasswordParam.id?.let { WebUtil.offlineUser(redisUtil, it) }
|
||||
userUpdatePasswordParam.id?.let { WebUtil.offlineUser(redisUtil, it) }
|
||||
} ?: let {
|
||||
throw NoRecordFoundException()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user