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 6451998..e6d0501 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 @@ -128,6 +128,30 @@ class EditController( fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam) = ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS, data = editService.update(toolUpdateParam)) + /** + * Submit tool review + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "提交工具审核") + @PostMapping("/{id}") + fun submit(@PathVariable id: Long): ResponseResult = + if (editService.submit(id)) ResponseResult.success(ResponseCode.TOOL_SUBMIT_SUCCESS) + else ResponseResult.fail(ResponseCode.TOOL_SUBMIT_ERROR) + + /** + * Cancel tool review + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "取消工具审核") + @PutMapping("/{id}") + fun cancel(@PathVariable id: Long): ResponseResult = + if (editService.cancel(id)) ResponseResult.success(ResponseCode.TOOL_CANCEL_SUCCESS) + else ResponseResult.fail(ResponseCode.TOOL_CANCEL_ERROR) + /** * 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 be1dae1..01d14af 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 @@ -58,10 +58,15 @@ enum class ResponseCode(val code: Int) { DATABASE_DUPLICATE_KEY(BusinessCode.DATABASE, 51), DATABASE_NO_RECORD_FOUND(BusinessCode.DATABASE, 52), + TOOL_SUBMIT_SUCCESS(BusinessCode.TOOL, 10), + TOOL_CANCEL_SUCCESS(BusinessCode.TOOL, 11), 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), + TOOL_NOT_UNDER_REVIEW(BusinessCode.TOOL, 52), + TOOL_HAS_UNPUBLISHED_VERSION(BusinessCode.TOOL, 53), + TOOL_HAS_BEEN_PUBLISHED(BusinessCode.TOOL, 54), + TOOL_SUBMIT_ERROR(BusinessCode.TOOL, 60), + TOOL_CANCEL_ERROR(BusinessCode.TOOL, 61), 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/ToolNotUnderReviewException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolNotUnderReviewException.kt new file mode 100644 index 0000000..586d71f --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolNotUnderReviewException.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.exception + +/** + * Tool not under review exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ +class ToolNotUnderReviewException : RuntimeException("Tool not 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 a3c85ef..2f4d155 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -222,6 +222,11 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.TOOL_UNDER_REVIEW, e.localizedMessage, null) } + is ToolNotUnderReviewException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.TOOL_NOT_UNDER_REVIEW, e.localizedMessage, null) + } + is ToolHasUnpublishedVersionException -> { logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.TOOL_HAS_UNPUBLISHED_VERSION, e.localizedMessage, null) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt index 7f8e197..31da2ef 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt @@ -100,6 +100,22 @@ interface IEditService : IService { */ fun detail(username: String, toolId: String, ver: String): ToolVo + /** + * Submit tool review + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun submit(id: Long): Boolean + + /** + * Cancel tool review + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun cancel(id: Long): Boolean + /** * Delete tool * 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 e7326c1..6d79f0e 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 @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.service.tool.impl import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper +import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.dao.DuplicateKeyException import org.springframework.stereotype.Service @@ -215,6 +216,30 @@ class EditServiceImpl( return toolList.first().let(ToolConverter::toolToToolVo) } + override fun submit(id: Long): Boolean { + val tool = getById(id) + if (tool.review == Tool.ReviewType.PROCESSING) { + throw ToolUnderReviewException() + } + if (tool.review == Tool.ReviewType.PASS || tool.publish != 0L) { + throw ToolHasBeenPublishedException() + } + + return update(KtUpdateWrapper(Tool()).eq(Tool::id, id).set(Tool::review, Tool.ReviewType.PROCESSING)) + } + + override fun cancel(id: Long): Boolean { + val tool = getById(id) + if (tool.review == Tool.ReviewType.PASS || tool.publish != 0L) { + throw ToolHasBeenPublishedException() + } + if (tool.review != Tool.ReviewType.PROCESSING) { + throw ToolNotUnderReviewException() + } + + return update(KtUpdateWrapper(Tool()).eq(Tool::id, id).set(Tool::review, Tool.ReviewType.NONE)) + } + @Transactional override fun delete(id: Long): Boolean { val tool = baseMapper.selectOne(