diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt index 82b2bfc..24e2715 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt @@ -1,16 +1,13 @@ package top.fatweb.oxygen.api.controller.tool import io.swagger.v3.oas.annotations.Operation -import org.springframework.web.bind.annotation.DeleteMapping -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PatchMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.PutMapping +import jakarta.validation.Valid +import org.springframework.web.bind.annotation.* import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult import top.fatweb.oxygen.api.param.tool.ToolManagementGetParam +import top.fatweb.oxygen.api.param.tool.ToolManagementPassParam import top.fatweb.oxygen.api.service.tool.IManagementService import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -40,7 +37,7 @@ class ManagementController( @GetMapping fun get(toolManagementGetParam: ToolManagementGetParam): ResponseResult> = ResponseResult.databaseSuccess(data = managementService.getPage(toolManagementGetParam)) - + /** * Pass tool review * @@ -49,8 +46,14 @@ class ManagementController( */ @Operation(summary = "通过审核") @PostMapping("/{id}") - fun pass(@PathVariable id: Long): ResponseResult = - ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS, data = managementService.pass(id)) + fun pass( + @PathVariable id: Long, + @RequestBody @Valid toolManagementPassParam: ToolManagementPassParam + ): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, + data = managementService.pass(id, toolManagementPassParam) + ) /** * Reject tool review @@ -71,7 +74,7 @@ class ManagementController( */ @Operation(summary = "下架") @PatchMapping("/{id}") - fun offShelve(@PathVariable id: Long):ResponseResult = + fun offShelve(@PathVariable id: Long): ResponseResult = ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS, data = managementService.offShelve(id)) /** diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt new file mode 100644 index 0000000..33460d4 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt @@ -0,0 +1,22 @@ +package top.fatweb.oxygen.api.param.tool + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank + +/** + * Pass tool in management parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +data class ToolManagementPassParam( + /** + * Dist + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "产物") + @field:NotBlank(message = "Dist can not be blank") + val dist: String? +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt index e7373ac..8be97b4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt @@ -3,6 +3,7 @@ package top.fatweb.oxygen.api.service.tool import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.oxygen.api.entity.tool.Tool import top.fatweb.oxygen.api.param.tool.ToolManagementGetParam +import top.fatweb.oxygen.api.param.tool.ToolManagementPassParam import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -19,7 +20,7 @@ interface IManagementService : IService { fun getPage(toolManagementGetParam: ToolManagementGetParam?): PageVo - fun pass(id: Long): ToolVo + fun pass(id: Long, toolManagementPassParam: ToolManagementPassParam): ToolVo fun reject(id: Long): ToolVo diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt index 45cb9fe..9e6ed3e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt @@ -10,17 +10,17 @@ import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.tool.ToolConverter import top.fatweb.oxygen.api.entity.tool.RToolCategory import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.entity.tool.ToolData import top.fatweb.oxygen.api.exception.NoRecordFoundException import top.fatweb.oxygen.api.exception.ToolHasNotBeenPublishedException import top.fatweb.oxygen.api.exception.ToolNotUnderReviewException import top.fatweb.oxygen.api.mapper.tool.ManagementMapper import top.fatweb.oxygen.api.param.tool.ToolManagementGetParam -import top.fatweb.oxygen.api.service.tool.IEditService +import top.fatweb.oxygen.api.param.tool.ToolManagementPassParam import top.fatweb.oxygen.api.service.tool.IManagementService import top.fatweb.oxygen.api.service.tool.IRToolCategoryService import top.fatweb.oxygen.api.service.tool.IToolDataService import top.fatweb.oxygen.api.util.PageUtil -import top.fatweb.oxygen.api.util.WebUtil import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolVo import java.time.LocalDateTime @@ -44,6 +44,7 @@ class ManagementServiceImpl( override fun getOne(id: Long): ToolVo = baseMapper.selectOne(id) ?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() + override fun getPage(toolManagementGetParam: ToolManagementGetParam?): PageVo { val toolIdsPage = Page(toolManagementGetParam?.currentPage ?: 1, toolManagementGetParam?.pageSize ?: 20) @@ -65,12 +66,16 @@ class ManagementServiceImpl( return ToolConverter.toolPageToToolPageVo(toolPage) } - override fun pass(id: Long): ToolVo { + override fun pass(id: Long, toolManagementPassParam: ToolManagementPassParam): ToolVo { val tool = this.getById(id) ?: throw NoRecordFoundException() if (tool.review !== Tool.ReviewType.PROCESSING) { throw ToolNotUnderReviewException() } + toolDataService.update( + KtUpdateWrapper(ToolData()).eq(ToolData::id, tool.distId).set(ToolData::data, toolManagementPassParam.dist) + ) + this.update( KtUpdateWrapper(Tool()) .eq(Tool::id, id) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt index d200bb4..ed11c75 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt @@ -44,7 +44,7 @@ class ToolCategoryServiceImpl : ServiceImpl(), override fun update(toolCategoryUpdateParam: ToolCategoryUpdateParam): ToolCategoryVo { val toolCategory = ToolCategoryConverter.toolCategoryUpdateParamToToolCategory(toolCategoryUpdateParam) - if (this.updateById(toolCategory)) { + if (!this.updateById(toolCategory)) { throw DatabaseUpdateException() }