From 04587fbb7a8363b18961ee7b4fc0fc9d5811df2e Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 1 Feb 2024 16:51:20 +0800 Subject: [PATCH] Implement update tool --- .../api/controller/tool/EditController.kt | 19 ++++- .../oxygen/api/entity/common/ResponseCode.kt | 3 + .../api/exception/DatabaseDeleteException.kt | 8 +++ .../api/exception/DatabaseInsertException.kt | 8 +++ .../api/exception/DatabaseSelectException.kt | 8 +++ .../api/exception/DatabaseUpdateException.kt | 8 +++ .../api/exception/IllegalVersionException.kt | 7 ++ .../exception/MatchSensitiveWordException.kt | 9 ++- ...uent.kt => RequestTooFrequentException.kt} | 3 +- .../ToolHasBeenPublishedException.kt | 10 +++ .../oxygen/api/exception/ToolHasPublish.kt | 3 - .../ToolHasUnpublishedVersionException.kt | 10 +++ .../api/exception/ToolUnderReviewException.kt | 10 +++ .../oxygen/api/handler/ExceptionHandler.kt | 17 ++++- .../oxygen/api/mapper/tool/EditMapper.kt | 2 +- .../permission/group/GroupDeleteParam.kt | 4 +- .../param/permission/role/RoleDeleteParam.kt | 4 +- .../param/permission/user/UserDeleteParam.kt | 4 +- .../oxygen/api/param/tool/ToolCreateParam.kt | 4 +- .../oxygen/api/param/tool/ToolUpdateParam.kt | 55 ++------------- .../oxygen/api/param/tool/ToolUpgradeParam.kt | 2 +- .../impl/AuthenticationServiceImpl.kt | 4 +- .../permission/impl/GroupServiceImpl.kt | 2 +- .../permission/impl/RoleServiceImpl.kt | 2 +- .../permission/impl/UserServiceImpl.kt | 2 +- .../api/service/tool/impl/EditServiceImpl.kt | 70 +++++++++++++++++-- src/main/resources/mapper/tool/EditMapper.xml | 1 - 27 files changed, 204 insertions(+), 75 deletions(-) rename src/main/kotlin/top/fatweb/oxygen/api/exception/{RequestTooFrequent.kt => RequestTooFrequentException.kt} (59%) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasBeenPublishedException.kt delete mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasPublish.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasUnpublishedVersionException.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/ToolUnderReviewException.kt diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt index 318fadd..6451998 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt @@ -7,6 +7,7 @@ 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.param.tool.ToolCreateParam +import top.fatweb.oxygen.api.param.tool.ToolUpdateParam import top.fatweb.oxygen.api.param.tool.ToolUpgradeParam import top.fatweb.oxygen.api.service.tool.IEditService import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo @@ -83,10 +84,13 @@ class EditController( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @Operation(summary = "更新工具") + @Operation(summary = "升级工具") @PatchMapping fun upgrade(@RequestBody @Valid toolUpgradeParam: ToolUpgradeParam): ResponseResult = - ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS, data = editService.upgrade(toolUpgradeParam)) + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, + data = editService.upgrade(toolUpgradeParam) + ) /** * Get personal tool @@ -113,6 +117,17 @@ class EditController( data = editService.detail(username, toolId, ver) ) + /** + * Update tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "更新工具") + @PutMapping + fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam) = + ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS, data = editService.update(toolUpdateParam)) + /** * Delete tool * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt index 738f9ae..be1dae1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt @@ -59,6 +59,9 @@ enum class ResponseCode(val code: Int) { DATABASE_NO_RECORD_FOUND(BusinessCode.DATABASE, 52), TOOL_ILLEGAL_VERSION(BusinessCode.TOOL, 50), + TOOL_UNDER_REVIEW(BusinessCode.TOOL, 51), + TOOL_HAS_UNPUBLISHED_VERSION(BusinessCode.TOOL, 52), + TOOL_HAS_BEEN_PUBLISHED(BusinessCode.TOOL, 53), API_AVATAR_SUCCESS(BusinessCode.API_AVATAR, 0), API_AVATAR_ERROR(BusinessCode.API_AVATAR, 50); diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt index f6926b2..cd1ea34 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt @@ -1,3 +1,11 @@ package top.fatweb.oxygen.api.exception +/** + * Database delete exception + * + * @param message Exception message + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ class DatabaseDeleteException(message: String = "Database delete failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt index 1744ea7..b3e301d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt @@ -1,3 +1,11 @@ package top.fatweb.oxygen.api.exception +/** + * Database insert exception + * + * @param message Exception message + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ class DatabaseInsertException(message: String = "Database insert failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt index e8e1d2b..1b5623b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt @@ -1,3 +1,11 @@ package top.fatweb.oxygen.api.exception +/** + * Database select exception + * + * @param message Exception message + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ class DatabaseSelectException(message: String = "Database select failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt index c2fa87c..43f6c09 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt @@ -1,3 +1,11 @@ package top.fatweb.oxygen.api.exception +/** + * Database update exception + * + * @param message Exception message + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ class DatabaseUpdateException(message: String = "Database update failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/IllegalVersionException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/IllegalVersionException.kt index 3ee96ae..b53fc99 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/IllegalVersionException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/IllegalVersionException.kt @@ -1,3 +1,10 @@ package top.fatweb.oxygen.api.exception +/** + * Illegal version exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ class IllegalVersionException : RuntimeException("Illegal Version") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/MatchSensitiveWordException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/MatchSensitiveWordException.kt index d428efb..dbf5cf6 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/MatchSensitiveWordException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/MatchSensitiveWordException.kt @@ -1,3 +1,10 @@ package top.fatweb.oxygen.api.exception -class MatchSensitiveWordException: RuntimeException("Match sensitive word") \ No newline at end of file +/** + * Match sensitive word exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ +class MatchSensitiveWordException : RuntimeException("Match sensitive word") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequent.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequentException.kt similarity index 59% rename from src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequent.kt rename to src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequentException.kt index be1f1e2..59a5b16 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequent.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequentException.kt @@ -5,5 +5,6 @@ package top.fatweb.oxygen.api.exception * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see RuntimeException */ -class RequestTooFrequent: RuntimeException("Request too frequent") \ No newline at end of file +class RequestTooFrequentException: RuntimeException("Request too frequent") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasBeenPublishedException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasBeenPublishedException.kt new file mode 100644 index 0000000..f80dfca --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasBeenPublishedException.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.exception + +/** + * Tool has been published exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ +class ToolHasBeenPublishedException : RuntimeException("Tool has been published") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasPublish.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasPublish.kt deleted file mode 100644 index 72998c2..0000000 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasPublish.kt +++ /dev/null @@ -1,3 +0,0 @@ -package top.fatweb.oxygen.api.exception - -class ToolHasPublish : RuntimeException("The tool has been published and cannot be modified") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasUnpublishedVersionException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasUnpublishedVersionException.kt new file mode 100644 index 0000000..0b4d41e --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasUnpublishedVersionException.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.exception + +/** + * Tool has unpublished version exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ +class ToolHasUnpublishedVersionException : RuntimeException("Has unpublished version") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolUnderReviewException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolUnderReviewException.kt new file mode 100644 index 0000000..83083f0 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolUnderReviewException.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.exception + +/** + * Tool under review exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ +class ToolUnderReviewException : RuntimeException("Tool under review") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt index e558606..a3c85ef 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -61,7 +61,7 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.SYSTEM_ARGUMENT_NOT_VALID, errorMessage, null) } - is RequestTooFrequent -> { + is RequestTooFrequentException -> { logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_TOO_FREQUENT, e.localizedMessage, null) } @@ -217,6 +217,21 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.TOOL_ILLEGAL_VERSION, e.localizedMessage, null) } + is ToolUnderReviewException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.TOOL_UNDER_REVIEW, e.localizedMessage, null) + } + + is ToolHasUnpublishedVersionException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.TOOL_HAS_UNPUBLISHED_VERSION, e.localizedMessage, null) + } + + is ToolHasBeenPublishedException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.TOOL_HAS_BEEN_PUBLISHED, e.localizedMessage, null) + } + /* Other */ is MatchSensitiveWordException -> { logger.debug(e.localizedMessage, e) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt index 567f741..d31a8eb 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt @@ -27,5 +27,5 @@ interface EditMapper : BaseMapper { @Param("toolId") toolId: String, @Param("ver") ver: String, @Param("operator") operator: String? - ): Tool? + ): List? } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupDeleteParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupDeleteParam.kt index f7ebe22..ff08c35 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupDeleteParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupDeleteParam.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.param.permission.group import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotEmpty /** * Delete group parameters @@ -17,5 +18,6 @@ data class GroupDeleteParam( * @since 1.0.0 */ @Schema(description = "用户组 ID 列表", required = true) - val ids: List + @field: NotEmpty(message = "Ids can not be empty") + val ids: List? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleDeleteParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleDeleteParam.kt index af400da..0704b2a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleDeleteParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleDeleteParam.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.param.permission.role import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotEmpty /** * Delete role parameters @@ -17,5 +18,6 @@ data class RoleDeleteParam( * @since 1.0.0 */ @Schema(description = "角色 ID 列表", required = true) - val ids: List + @field: NotEmpty(message = "Ids can not be empty") + val ids: List? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserDeleteParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserDeleteParam.kt index 486d39c..0a61709 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserDeleteParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserDeleteParam.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.param.permission.user import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotEmpty /** * Delete user parameters @@ -17,5 +18,6 @@ data class UserDeleteParam( * @since 1.0.0 */ @Schema(description = "用户 ID 列表", required = true) - val ids: List + @field: NotEmpty(message = "Ids can not be empty") + val ids: List? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt index 8cd4e83..3cb0361 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt @@ -86,7 +86,7 @@ data class ToolCreateParam( */ @Schema(description = "关键词", required = true) @field: NotEmpty(message = "Keywords can not be empty") - val keywords: List, + val keywords: List?, /** * Categories @@ -96,5 +96,5 @@ data class ToolCreateParam( */ @Schema(description = "类别", required = true) @field: NotEmpty(message = "Categories can not be empty") - val categories: List + val categories: List? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt index f341be8..935ceef 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt @@ -2,7 +2,6 @@ package top.fatweb.oxygen.api.param.tool import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotNull -import jakarta.validation.constraints.Pattern /** * Update tool parameters @@ -10,6 +9,7 @@ import jakarta.validation.constraints.Pattern * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ +@Schema(description = "更新工具请求参数") data class ToolUpdateParam( /** * ID @@ -31,17 +31,13 @@ data class ToolUpdateParam( val name: String?, /** - * Tool ID + * Icon * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @Schema(description = "工具唯一 ID", example = "tool_a") - @field: Pattern( - regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", - message = "Ver can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" - ) - val toolId: String?, + @Schema(description = "图标") + val icon: String?, /** * Description @@ -52,34 +48,6 @@ data class ToolUpdateParam( @Schema(description = "简介") val description: String?, - /** - * Author ID - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "作者 ID") - val authorId: Long?, - - /** - * Version - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "版本", example = "1.0.3") - @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") - val ver: String?, - - /** - * Privately - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "私有", allowableValues = ["true", "false"]) - val privately: Boolean?, - /** * Keywords * @@ -87,7 +55,7 @@ data class ToolUpdateParam( * @since 1.0.0 */ @Schema(description = "关键词") - val keywords: List, + val keywords: List?, /** * Categories @@ -96,7 +64,7 @@ data class ToolUpdateParam( * @since 1.0.0 */ @Schema(description = "类别") - val categories: List, + val categories: List?, /** * Source @@ -105,14 +73,5 @@ data class ToolUpdateParam( * @since 1.0.0 */ @Schema(description = "源码") - val source: String?, - - /** - * Dist - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "产物") - val dist: String? + val source: String? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt index eb140f2..e3cca51 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt @@ -10,7 +10,7 @@ import jakarta.validation.constraints.Pattern * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@Schema(description = "更新工具请求参数") +@Schema(description = "升级工具请求参数") data class ToolUpgradeParam( /** * Tool ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt index f9e4982..b83dbe5 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -106,7 +106,7 @@ class AuthenticationServiceImpl( if (LocalDateTime.ofInstant(Instant.ofEpochMilli(user.verify!!.split("-").first().toLong()), ZoneOffset.UTC) .isAfter(LocalDateTime.now(ZoneOffset.UTC).minusMinutes(5)) ) { - throw RequestTooFrequent() + throw RequestTooFrequentException() } user.verify = @@ -158,7 +158,7 @@ class AuthenticationServiceImpl( if (LocalDateTime.ofInstant(Instant.ofEpochMilli(it.split("-").first().toLong()), ZoneOffset.UTC) .isAfter(LocalDateTime.now(ZoneOffset.UTC).minusMinutes(5)) ) { - throw RequestTooFrequent() + throw RequestTooFrequentException() } } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt index d81da51..416bc65 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt @@ -144,7 +144,7 @@ class GroupServiceImpl( override fun delete(groupDeleteParam: GroupDeleteParam) { baseMapper.deleteBatchIds(groupDeleteParam.ids) rRoleGroupService.remove(KtQueryWrapper(RRoleGroup()).`in`(RRoleGroup::groupId, groupDeleteParam.ids)) - offlineUser(*groupDeleteParam.ids.toLongArray()) + offlineUser(*groupDeleteParam.ids!!.toLongArray()) } private fun offlineUser(vararg groupIds: Long) { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt index 8ea381c..49859c3 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt @@ -151,7 +151,7 @@ class RoleServiceImpl( override fun delete(roleDeleteParam: RoleDeleteParam) { baseMapper.deleteBatchIds(roleDeleteParam.ids) rPowerRoleService.remove(KtQueryWrapper(RPowerRole()).`in`(RPowerRole::roleId, roleDeleteParam.ids)) - offlineUser(*roleDeleteParam.ids.toLongArray()) + offlineUser(*roleDeleteParam.ids!!.toLongArray()) } private fun getFullPowerIds(powerIds: List): Set { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt index b698886..912413a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt @@ -276,7 +276,7 @@ class UserServiceImpl( @Transactional override fun delete(userDeleteParam: UserDeleteParam) { - val ids = userDeleteParam.ids.filter { it != 0L } + val ids = userDeleteParam.ids!!.filter { it != 0L } if (ids.isEmpty()) { return } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index f0ee779..e7326c1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -9,8 +9,7 @@ import top.fatweb.oxygen.api.converter.tool.ToolCategoryConverter import top.fatweb.oxygen.api.converter.tool.ToolConverter import top.fatweb.oxygen.api.converter.tool.ToolTemplateConverter import top.fatweb.oxygen.api.entity.tool.* -import top.fatweb.oxygen.api.exception.IllegalVersionException -import top.fatweb.oxygen.api.exception.NoRecordFoundException +import top.fatweb.oxygen.api.exception.* import top.fatweb.oxygen.api.mapper.tool.EditMapper import top.fatweb.oxygen.api.param.tool.ToolCreateParam import top.fatweb.oxygen.api.param.tool.ToolUpdateParam @@ -81,7 +80,7 @@ class EditServiceImpl( this.save(tool) - toolCreateParam.categories.forEach { + toolCreateParam.categories!!.forEach { toolCategoryService.getById(it) ?: throw NoRecordFoundException() rToolCategoryService.save(RToolCategory().apply { toolId = tool.id @@ -95,6 +94,12 @@ class EditServiceImpl( @Transactional override fun upgrade(toolUpgradeParam: ToolUpgradeParam): ToolVo { val originalTool = this.detail("!", toolUpgradeParam.toolId!!, "latest") + if (originalTool.review == Tool.ReviewType.PROCESSING) { + throw ToolUnderReviewException() + } + if (originalTool.review != Tool.ReviewType.PASS || originalTool.publish == 0L) { + throw ToolHasUnpublishedVersionException() + } val originalVersion = originalTool.ver!! if (originalVersion.split(".").map(String::toLong).joinToString(".") == toolUpgradeParam.ver!!.split(".") @@ -141,7 +146,57 @@ class EditServiceImpl( @Transactional override fun update(toolUpdateParam: ToolUpdateParam): ToolVo { - TODO("Not yet implemented") + val tool = getById(toolUpdateParam.id) + if (tool.review == Tool.ReviewType.PROCESSING) { + throw ToolUnderReviewException() + } + if (tool.review == Tool.ReviewType.PASS || tool.publish != 0L) { + throw ToolHasBeenPublishedException() + } + + this.updateById(Tool().apply { + id = toolUpdateParam.id + name = toolUpdateParam.name + icon = toolUpdateParam.icon + description = toolUpdateParam.description + keywords = toolUpdateParam.keywords + }) + + if (!toolUpdateParam.categories.isNullOrEmpty()) { + val oldCategories = rToolCategoryService.list( + KtQueryWrapper(RToolCategory()).select(RToolCategory::categoryId).eq(RToolCategory::toolId, tool.id) + ).map(RToolCategory::categoryId) + val addCategories = HashSet() + val removeCategories = HashSet() + toolUpdateParam.categories.forEach(addCategories::add) + oldCategories.forEach { + it?.let(removeCategories::add) + } + removeCategories.removeAll(addCategories) + oldCategories.toSet().let(addCategories::removeAll) + + removeCategories.forEach { + rToolCategoryService.remove( + KtQueryWrapper(RToolCategory()).eq( + RToolCategory::toolId, tool.id + ).eq(RToolCategory::categoryId, it) + ) + } + + addCategories.forEach { + rToolCategoryService.save(RToolCategory().apply { + toolId = tool.id + categoryId = it + }) + } + + toolDataService.updateById(ToolData().apply { + id = tool.sourceId + data = toolUpdateParam.source + }) + } + + return this.getOne(tool.id!!) } override fun get(): List = @@ -152,9 +207,12 @@ class EditServiceImpl( if (username == "!" && WebUtil.getLoginUserId() == null) { throw NoRecordFoundException() } + val toolList = baseMapper.detail(username, toolId, ver, WebUtil.getLoginUsername()) + if (toolList.isNullOrEmpty()) { + throw NoRecordFoundException() + } - return baseMapper.detail(username, toolId, ver, WebUtil.getLoginUsername())?.let(ToolConverter::toolToToolVo) - ?: throw NoRecordFoundException() + return toolList.first().let(ToolConverter::toolToToolVo) } @Transactional diff --git a/src/main/resources/mapper/tool/EditMapper.xml b/src/main/resources/mapper/tool/EditMapper.xml index 9250171..1303e22 100644 --- a/src/main/resources/mapper/tool/EditMapper.xml +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -208,7 +208,6 @@ order by t_b_tool_main.id desc - limit 1