Complete core functions #9
@@ -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<Nothing> =
|
||||
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<Nothing> =
|
||||
if (editService.cancel(id)) ResponseResult.success(ResponseCode.TOOL_CANCEL_SUCCESS)
|
||||
else ResponseResult.fail(ResponseCode.TOOL_CANCEL_ERROR)
|
||||
|
||||
/**
|
||||
* Delete tool
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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")
|
||||
@@ -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)
|
||||
|
||||
@@ -100,6 +100,22 @@ interface IEditService : IService<Tool> {
|
||||
*/
|
||||
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
|
||||
*
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user