From bdd0197d78d998bbc05cc5e19187b16582b518a2 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 26 Apr 2024 16:31:44 +0800 Subject: [PATCH 1/9] Fix(EditService): Fix get wrong tool detail Fix get wrong tool detail in source page --- .../kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt | 2 +- .../fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt | 7 ++----- src/main/resources/mapper/tool/EditMapper.xml | 3 +++ 3 files changed, 6 insertions(+), 6 deletions(-) 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 f874483..2fb8321 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 @@ -69,5 +69,5 @@ interface EditMapper : BaseMapper { @Param("ver") ver: String, @Param("platform") platform: ToolBase.Platform, @Param("operator") operator: String? - ): List? + ): Tool? } \ No newline at end of file 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 44165cb..c5ef9d3 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 @@ -219,12 +219,9 @@ class EditServiceImpl( if (username == "!" && WebUtil.getLoginUserId() == null) { throw NoRecordFoundException() } - val toolList = baseMapper.selectDetail(username, toolId, ver, platform, WebUtil.getLoginUsername()) - if (toolList.isNullOrEmpty()) { - throw NoRecordFoundException() - } - return toolList.first().let(ToolConverter::toolToToolVo) + return baseMapper.selectDetail(username, toolId, ver, platform, WebUtil.getLoginUsername()) + ?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() } override fun submit(id: Long): Boolean { diff --git a/src/main/resources/mapper/tool/EditMapper.xml b/src/main/resources/mapper/tool/EditMapper.xml index ca46957..c48c967 100644 --- a/src/main/resources/mapper/tool/EditMapper.xml +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -195,6 +195,7 @@ and tsu.username = #{username} + and t_b_tool_main.publish != 0 @@ -206,11 +207,13 @@ and tsu.username = #{username} + and t_b_tool_main.publish != 0 order by t_b_tool_main.id desc + limit 1 \ No newline at end of file -- 2.49.1 From 4527944a219cfe9dd8d3c6be95c7510b820bb1be Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 26 Apr 2024 16:35:22 +0800 Subject: [PATCH 2/9] Fix(ToolParam): Fix wrong validate message Fix wrong validate message in ToolCreateParam and ToolUpgradeParam --- .../kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt | 2 +- .../kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 0f8b666..379b51e 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 @@ -38,7 +38,7 @@ data class ToolCreateParam( @field: NotBlank(message = "ToolId can not be blank") @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}\$'" + message = "ToolId can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" ) var toolId: 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 321c1ff..1863b31 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 @@ -27,7 +27,7 @@ data class ToolUpgradeParam( @field: NotBlank(message = "ToolId can not be blank") @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}\$'" + message = "ToolId can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" ) var toolId: String?, -- 2.49.1 From bc8b0b8f9f043ddb2f082904cda95b14b1f00ed0 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 26 Apr 2024 16:45:16 +0800 Subject: [PATCH 3/9] Refactor(Entity): Add implement Serializable Add implement Serializable to entity --- src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt | 3 ++- src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt | 3 ++- .../kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt | 3 ++- src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt | 3 ++- .../kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt index 6788c81..848c2be 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.* import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler import com.fasterxml.jackson.annotation.JsonValue import top.fatweb.oxygen.api.entity.permission.User +import java.io.Serializable import java.time.LocalDateTime /** @@ -13,7 +14,7 @@ import java.time.LocalDateTime * @since 1.0.0 */ @TableName("t_b_tool_main", autoResultMap = true) -class Tool { +class Tool : Serializable { /** * Tool review type enum * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt index 9de0aa0..94765cf 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.entity.tool import com.baomidou.mybatisplus.annotation.* import com.fasterxml.jackson.annotation.JsonValue +import java.io.Serializable import java.time.LocalDateTime /** @@ -11,7 +12,7 @@ import java.time.LocalDateTime * @since 1.0.0 */ @TableName("t_b_tool_base") -class ToolBase { +class ToolBase : Serializable { /** * Platform enum * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt index f111e1d..37246b1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.entity.tool import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable import java.time.LocalDateTime /** @@ -10,7 +11,7 @@ import java.time.LocalDateTime * @since 1.0.0 */ @TableName("t_b_tool_category") -class ToolCategory { +class ToolCategory : Serializable { /** * ID * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt index d576b23..dd1f0dd 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.entity.tool import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable import java.time.LocalDateTime /** @@ -10,7 +11,7 @@ import java.time.LocalDateTime * @since 1.0.0 */ @TableName("t_b_tool_data") -class ToolData { +class ToolData : Serializable { /** * ID * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt index 09e8bde..d82358b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.entity.tool import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable import java.time.LocalDateTime /** @@ -10,7 +11,7 @@ import java.time.LocalDateTime * @since 1.0.0 */ @TableName("t_b_tool_template") -class ToolTemplate { +class ToolTemplate : Serializable { /** * ID * -- 2.49.1 From 96afb185e7f6105ad9b32266ce6c40efdaf2c772 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 26 Apr 2024 16:55:35 +0800 Subject: [PATCH 4/9] Fix(StoreMapper): Fix get wrong tools Fix unable to get tools after creating a new version bug --- src/main/resources/mapper/tool/StoreMapper.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/mapper/tool/StoreMapper.xml b/src/main/resources/mapper/tool/StoreMapper.xml index f4b4e02..d309167 100644 --- a/src/main/resources/mapper/tool/StoreMapper.xml +++ b/src/main/resources/mapper/tool/StoreMapper.xml @@ -8,12 +8,12 @@ from (select *, row_number() over (partition by t_b_tool_main.tool_id, t_b_tool_main.author_id order by t_b_tool_main.id desc) as rn1 from t_b_tool_main where t_b_tool_main.deleted = 0 + and t_b_tool_main.publish != 0 and t_b_tool_main.review = 'PASS' ) as temp0 where temp0.rn1 = 1 ) as temp1 left join json_table(json_extract(temp1.keywords, '$[*]'), '$[*]' columns (keyword varchar(50) path '$')) as tk on true - and temp1.publish != 0 and temp1.review = 'PASS' and ( temp1.name like concat('%', #{searchValue}, '%') @@ -45,13 +45,13 @@ from (select *, row_number() over (partition by t_b_tool_main.tool_id, t_b_tool_main.author_id order by t_b_tool_main.id desc) as rn1 from t_b_tool_main where t_b_tool_main.deleted = 0 + and t_b_tool_main.publish != 0 + and t_b_tool_main.review = 'PASS' ) as temp0 where temp0.rn1 = 1 ) as temp1 left join (select * from t_s_user where deleted = 0) as tsu on tsu.id = temp1.author_id - where temp1.publish != 0 - and temp1.review = 'PASS' - and tsu.username = #{username} + where tsu.username = #{username} order by temp1.publish desc ) as temp2 where temp2.rn2 = 1 -- 2.49.1 From 5c3484a22ddf637338fec9ec3f8583f539461ae3 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 26 Apr 2024 18:07:49 +0800 Subject: [PATCH 5/9] Feat(ToolStore): Add tool favorite controller Add controller to add and remove favorite tool --- .../api/controller/tool/EditController.kt | 40 ++++++++- .../api/converter/tool/ToolConverter.kt | 3 +- .../oxygen/api/entity/common/ResponseCode.kt | 1 + .../top/fatweb/oxygen/api/entity/tool/Tool.kt | 11 ++- .../oxygen/api/entity/tool/ToolFavorite.kt | 81 +++++++++++++++++++ .../api/exception/RecordAlreadyExists.kt | 10 +++ .../oxygen/api/handler/ExceptionHandler.kt | 11 ++- .../oxygen/api/mapper/tool/StoreMapper.kt | 2 +- .../api/mapper/tool/ToolFavoriteMapper.kt | 8 ++ .../api/param/tool/ToolFavoriteAddParam.kt | 53 ++++++++++++ .../api/param/tool/ToolFavoriteRemoveParam.kt | 53 ++++++++++++ .../oxygen/api/service/tool/IEditService.kt | 24 +++++- .../api/service/tool/IToolFavoriteService.kt | 6 ++ .../api/service/tool/impl/EditServiceImpl.kt | 46 ++++++++++- .../api/service/tool/impl/StoreServiceImpl.kt | 5 +- .../tool/impl/ToolFavoriteServiceImpl.kt | 10 +++ .../top/fatweb/oxygen/api/vo/tool/ToolVo.kt | 11 ++- ..._240426__Add_table_'t_b_tool_favorite'.sql | 13 +++ .../mapper/tool/ManagementMapper.xml | 1 + .../resources/mapper/tool/StoreMapper.xml | 11 ++- .../mapper/tool/ToolFavoriteMapper.xml | 10 +++ 21 files changed, 389 insertions(+), 21 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolFavorite.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/RecordAlreadyExists.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteAddParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteRemoveParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt create mode 100644 src/main/resources/db/migration/master/V1_0_0_240426__Add_table_'t_b_tool_favorite'.sql create mode 100644 src/main/resources/mapper/tool/ToolFavoriteMapper.xml 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 c805d84..73720dd 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 @@ -8,9 +8,7 @@ import top.fatweb.oxygen.api.annotation.Trim import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult import top.fatweb.oxygen.api.entity.tool.ToolBase -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.param.tool.* import top.fatweb.oxygen.api.service.tool.IEditService import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo @@ -207,4 +205,40 @@ class EditController( fun delete(@PathVariable id: Long): ResponseResult = if (editService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) + + /** + * Add favorite tool + * + * @param toolFavoriteAddParam Add favorite tool parameters + * @return Response object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolFavoriteAddParam + * @see ResponseResult + */ + @Operation(summary = "收藏工具") + @PostMapping("/favorite") + fun addFavorite(@RequestBody toolFavoriteAddParam: ToolFavoriteAddParam): ResponseResult { + editService.addFavorite(toolFavoriteAddParam) + + return ResponseResult.databaseSuccess(ResponseCode.DATABASE_INSERT_SUCCESS) + } + + /** + * Remove favorite tool + * + * @param toolFavoriteRemoveParam Remove favorite tool parameters + * @return Response object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolFavoriteRemoveParam + * @see ResponseResult + */ + @Operation(summary = "收藏工具") + @DeleteMapping("/favorite") + fun addFavorite(@RequestBody toolFavoriteRemoveParam: ToolFavoriteRemoveParam): ResponseResult { + editService.removeFavorite(toolFavoriteRemoveParam) + + return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt index 1402af2..19f54ba 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt @@ -41,7 +41,8 @@ object ToolConverter { publish = tool.publish, review = tool.review, createTime = tool.createTime, - updateTime = tool.updateTime + updateTime = tool.updateTime, + favorite = tool.favorite == 1 ) /** 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 e61be09..c95a4a5 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 @@ -61,6 +61,7 @@ enum class ResponseCode(val code: Int) { DATABASE_EXECUTE_ERROR(BusinessCode.DATABASE, 50), DATABASE_DUPLICATE_KEY(BusinessCode.DATABASE, 51), DATABASE_NO_RECORD_FOUND(BusinessCode.DATABASE, 52), + DATABASE_RECORD_ALREADY_EXISTS(BusinessCode.DATABASE, 53), TOOL_SUBMIT_SUCCESS(BusinessCode.TOOL, 10), TOOL_CANCEL_SUCCESS(BusinessCode.TOOL, 11), diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt index 848c2be..947f2d0 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt @@ -247,7 +247,16 @@ class Tool : Serializable { @TableField(exist = false) var dist: ToolData? = null + /** + * Favorite + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(exist = false) + var favorite: Int? = null + override fun toString(): String { - return "Tool(id=$id, name=$name, toolId=$toolId, icon=$icon, platform=$platform, description=$description, baseId=$baseId, authorId=$authorId, ver=$ver, keywords=$keywords, sourceId=$sourceId, distId=$distId, entryPoint=$entryPoint, publish=$publish, review=$review, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, author=$author, base=$base, categories=$categories, source=$source, dist=$dist)" + return "Tool(id=$id, name=$name, toolId=$toolId, icon=$icon, platform=$platform, description=$description, baseId=$baseId, authorId=$authorId, ver=$ver, keywords=$keywords, sourceId=$sourceId, distId=$distId, entryPoint=$entryPoint, publish=$publish, review=$review, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, author=$author, base=$base, categories=$categories, source=$source, dist=$dist, favorite=$favorite)" } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolFavorite.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolFavorite.kt new file mode 100644 index 0000000..56c7f18 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolFavorite.kt @@ -0,0 +1,81 @@ +package top.fatweb.oxygen.api.entity.tool + +import com.baomidou.mybatisplus.annotation.TableField +import com.baomidou.mybatisplus.annotation.TableId +import com.baomidou.mybatisplus.annotation.TableLogic +import com.baomidou.mybatisplus.annotation.TableName +import com.baomidou.mybatisplus.annotation.Version +import java.io.Serializable + +@TableName("t_b_tool_favorite") +class ToolFavorite : Serializable { + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableId("id") + var id: Long? = null + + /** + * User ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("user_id") + var userId: Long? = null + + /** + * Username + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("username") + var username: String? = null + + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("tool_id") + var toolId: String? = null + + /** + * Platform + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBase.Platform + */ + @TableField("platform") + var platform: ToolBase.Platform? = null + + /** + * Deleted + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("version") + @Version + var version: Int? = null + + override fun toString(): String { + return "ToolFavorite(id=$id, userId=$userId, username=$username, toolId=$toolId, platform=$platform, deleted=$deleted, version=$version)" + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/RecordAlreadyExists.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/RecordAlreadyExists.kt new file mode 100644 index 0000000..20aaf88 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/RecordAlreadyExists.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.exception + +/** + * Record already exists exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ +class RecordAlreadyExists : RuntimeException("Record already exists") \ 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 d9969c0..587f5a1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -177,7 +177,11 @@ class ExceptionHandler { is TwoFactorVerificationCodeErrorException -> { logger.debug(e.localizedMessage, e) - ResponseResult.fail(ResponseCode.PERMISSION_TWO_FACTOR_VERIFICATION_CODE_ERROR, e.localizedMessage, null) + ResponseResult.fail( + ResponseCode.PERMISSION_TWO_FACTOR_VERIFICATION_CODE_ERROR, + e.localizedMessage, + null + ) } /* SQL */ @@ -226,6 +230,11 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.DATABASE_EXECUTE_ERROR, e.localizedMessage, null) } + is RecordAlreadyExists -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.DATABASE_RECORD_ALREADY_EXISTS, e.localizedMessage, null) + } + /* Tool */ is IllegalVersionException -> { logger.debug(e.localizedMessage, e) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt index 78e6449..786f58e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt @@ -60,5 +60,5 @@ interface StoreMapper : BaseMapper { * @since 1.0.0 * @see Tool */ - fun selectListByAuthorToolIds(@Param("ids") ids: List): List + fun selectListByAuthorToolIds(@Param("ids") ids: List, @Param("operator") operator: Long?): List } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt new file mode 100644 index 0000000..69d2d9c --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt @@ -0,0 +1,8 @@ +package top.fatweb.oxygen.api.mapper.tool + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.oxygen.api.entity.tool.ToolFavorite + +@Mapper +interface ToolFavoriteMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteAddParam.kt new file mode 100644 index 0000000..3a7537c --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteAddParam.kt @@ -0,0 +1,53 @@ +package top.fatweb.oxygen.api.param.tool + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import top.fatweb.oxygen.api.annotation.Trim +import top.fatweb.oxygen.api.entity.tool.ToolBase + +/** + * Add favorite tool parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +data class ToolFavoriteAddParam( + /** + * Username + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Trim + @Schema(description = "用户名", required = true) + @field: NotBlank(message = "Username cannot be blank") + var username: String?, + + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Trim + @Schema(description = "工具唯一 ID", required = true) + @field: NotBlank(message = "ToolId cannot be blank") + @field: Pattern( + regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", + message = "ToolId can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" + ) + var toolId: String?, + + /** + * Platform + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBase.Platform + */ + @Schema(description = "平台") + @field:NotNull(message = "Platform can not be null") + val platform: ToolBase.Platform? +) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteRemoveParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteRemoveParam.kt new file mode 100644 index 0000000..3ae65c9 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteRemoveParam.kt @@ -0,0 +1,53 @@ +package top.fatweb.oxygen.api.param.tool + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import top.fatweb.oxygen.api.annotation.Trim +import top.fatweb.oxygen.api.entity.tool.ToolBase + +/** + * Remove favorite tool parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +data class ToolFavoriteRemoveParam( + /** + * Username + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Trim + @Schema(description = "用户名", required = true) + @field: NotBlank(message = "Username cannot be blank") + var username: String?, + + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Trim + @Schema(description = "工具唯一 ID", required = true) + @field: NotBlank(message = "ToolId cannot be blank") + @field: Pattern( + regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", + message = "ToolId can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" + ) + var toolId: String?, + + /** + * Platform + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBase.Platform + */ + @Schema(description = "平台") + @field:NotNull(message = "Platform can not be null") + val platform: ToolBase.Platform? +) \ No newline at end of file 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 0c41807..774031c 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 @@ -3,9 +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.entity.tool.ToolBase -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.param.tool.* import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -151,4 +149,24 @@ interface IEditService : IService { * @since 1.0.0 */ fun delete(id: Long): Boolean + + /*** + * Add favorite + * + * @param toolFavoriteAddParam Add favorite tool parameters + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolFavoriteAddParam + */ + fun addFavorite(toolFavoriteAddParam: ToolFavoriteAddParam) + + /*** + * Remove favorite tool + * + * @param toolFavoriteRemoveParam Remove favorite tool parameters + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolFavoriteRemoveParam + */ + fun removeFavorite(toolFavoriteRemoveParam: ToolFavoriteRemoveParam) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt new file mode 100644 index 0000000..59cf54c --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt @@ -0,0 +1,6 @@ +package top.fatweb.oxygen.api.service.tool + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.oxygen.api.entity.tool.ToolFavorite + +interface IToolFavoriteService : IService \ No newline at end of file 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 c5ef9d3..d7958f9 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 @@ -12,9 +12,7 @@ import top.fatweb.oxygen.api.converter.tool.ToolTemplateConverter import top.fatweb.oxygen.api.entity.tool.* 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 -import top.fatweb.oxygen.api.param.tool.ToolUpgradeParam +import top.fatweb.oxygen.api.param.tool.* import top.fatweb.oxygen.api.service.tool.* import top.fatweb.oxygen.api.util.WebUtil import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo @@ -36,7 +34,8 @@ class EditServiceImpl( private val toolTemplateService: IToolTemplateService, private val toolCategoryService: IToolCategoryService, private val toolDataService: IToolDataService, - private val rToolCategoryService: IRToolCategoryService + private val rToolCategoryService: IRToolCategoryService, + private val toolFavoriteService: IToolFavoriteService ) : ServiceImpl(), IEditService { override fun getTemplate(platform: ToolBase.Platform): List = toolTemplateService.list( @@ -259,4 +258,43 @@ class EditServiceImpl( rToolCategoryService.remove(KtQueryWrapper(RToolCategory()).eq(RToolCategory::toolId, tool.id)) return this.removeById(id) } + + @Transactional + override fun addFavorite(toolFavoriteAddParam: ToolFavoriteAddParam) { + if (toolFavoriteService.exists( + KtQueryWrapper(ToolFavorite()) + .eq(ToolFavorite::userId, WebUtil.getLoginUserId()) + .eq(ToolFavorite::username, toolFavoriteAddParam.username) + .eq(ToolFavorite::toolId, toolFavoriteAddParam.toolId) + .eq(ToolFavorite::platform, toolFavoriteAddParam.platform) + ) + ) { + throw RecordAlreadyExists() + } + + this.detail(toolFavoriteAddParam.username!!, toolFavoriteAddParam.toolId!!, "latest", toolFavoriteAddParam.platform!!) + + toolFavoriteService.save( + ToolFavorite().apply { + userId = WebUtil.getLoginUserId() + username = toolFavoriteAddParam.username + toolId = toolFavoriteAddParam.toolId + platform = toolFavoriteAddParam.platform + } + ) + } + + @Transactional + override fun removeFavorite(toolFavoriteRemoveParam: ToolFavoriteRemoveParam) { + if (!toolFavoriteService.remove( + KtQueryWrapper(ToolFavorite()) + .eq(ToolFavorite::userId, WebUtil.getLoginUserId()) + .eq(ToolFavorite::username, toolFavoriteRemoveParam.username) + .eq(ToolFavorite::toolId, toolFavoriteRemoveParam.toolId) + .eq(ToolFavorite::platform, toolFavoriteRemoveParam.platform) + ) + ) { + throw NoRecordFoundException() + } + } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt index 7139e56..747526f 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt @@ -9,6 +9,7 @@ import top.fatweb.oxygen.api.mapper.tool.StoreMapper import top.fatweb.oxygen.api.param.PageSortParam import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam import top.fatweb.oxygen.api.service.tool.IStoreService +import top.fatweb.oxygen.api.util.WebUtil import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -31,7 +32,7 @@ class StoreServiceImpl : ServiceImpl(), IStoreService { val toolIdsIPage = baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam?.searchValue) val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) if (toolIdsIPage.total > 0) { - toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records)) + toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records, WebUtil.getLoginUserId())) } return ToolConverter.toolPageToToolPageVo(toolPage) @@ -44,7 +45,7 @@ class StoreServiceImpl : ServiceImpl(), IStoreService { val toolIdsIPage = baseMapper.selectAuthorToolIdPageByUsername(toolIdsPage, username) val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) if (toolIdsIPage.total > 0) { - toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records)) + toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records, WebUtil.getLoginUserId())) } return ToolConverter.toolPageToToolPageVo(toolPage) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt new file mode 100644 index 0000000..7ac062a --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.service.tool.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.oxygen.api.entity.tool.ToolFavorite +import top.fatweb.oxygen.api.mapper.tool.ToolFavoriteMapper +import top.fatweb.oxygen.api.service.tool.IToolFavoriteService + +@Service +class ToolFavoriteServiceImpl : ServiceImpl(), IToolFavoriteService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt index 6cce238..3be8f47 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt @@ -184,5 +184,14 @@ data class ToolVo( * @see LocalDateTime */ @Schema(description = "修改时间", example = "1900-01-01T00:00:00.000Z") - val updateTime: LocalDateTime? + val updateTime: LocalDateTime?, + + /** + * Favorite + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "收藏") + val favorite: Boolean? ) \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240426__Add_table_'t_b_tool_favorite'.sql b/src/main/resources/db/migration/master/V1_0_0_240426__Add_table_'t_b_tool_favorite'.sql new file mode 100644 index 0000000..20c051e --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_240426__Add_table_'t_b_tool_favorite'.sql @@ -0,0 +1,13 @@ +drop table if exists t_b_tool_favorite; + +create table if not exists t_b_tool_favorite +( + id bigint not null primary key, + user_id bigint not null comment '用户 ID', + username varchar(20) not null comment '用户名', + tool_id varchar(50) not null comment '工具 ID', + platform varchar(20) not null comment '平台', + deleted bigint not null default 0, + version int not null default 0, + constraint t_b_tool_favorite_unique_user_id_username_tool_id_platform unique (user_id, username, tool_id, platform, deleted) +) comment '工具-收藏表'; \ No newline at end of file diff --git a/src/main/resources/mapper/tool/ManagementMapper.xml b/src/main/resources/mapper/tool/ManagementMapper.xml index b2e6e71..a5f7b2f 100644 --- a/src/main/resources/mapper/tool/ManagementMapper.xml +++ b/src/main/resources/mapper/tool/ManagementMapper.xml @@ -237,6 +237,7 @@ + and tbtm.rn = 1 + + + + + + + + + -- 2.49.1 From f5b6687d97ee763b4bf033880eaeaad3c44832b4 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sat, 27 Apr 2024 16:32:13 +0800 Subject: [PATCH 6/9] Feat(PersonalTool): Add pagination Add pagination to personal tool management --- .../api/controller/tool/EditController.kt | 9 +++++-- .../oxygen/api/mapper/tool/EditMapper.kt | 20 ++++++++++++--- .../oxygen/api/mapper/tool/StoreMapper.kt | 6 ++--- .../api/mapper/tool/ToolFavoriteMapper.kt | 8 ++++++ .../oxygen/api/service/tool/IEditService.kt | 9 +++++-- .../oxygen/api/service/tool/IStoreService.kt | 13 +++++++++- .../api/service/tool/IToolFavoriteService.kt | 8 ++++++ .../api/service/tool/impl/EditServiceImpl.kt | 25 ++++++++++++++++--- .../api/service/tool/impl/StoreServiceImpl.kt | 6 ++--- .../tool/impl/ToolFavoriteServiceImpl.kt | 10 ++++++++ src/main/resources/mapper/tool/EditMapper.xml | 25 ++++++++++++++++--- 11 files changed, 117 insertions(+), 22 deletions(-) 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 73720dd..ef150b4 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 @@ -8,8 +8,10 @@ import top.fatweb.oxygen.api.annotation.Trim import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult import top.fatweb.oxygen.api.entity.tool.ToolBase +import top.fatweb.oxygen.api.param.PageSortParam import top.fatweb.oxygen.api.param.tool.* import top.fatweb.oxygen.api.service.tool.IEditService +import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -111,13 +113,16 @@ class EditController( * @return Response object includes tool list * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see PageSortParam * @see ResponseResult + * @see PageVo * @see ToolVo */ + @Trim @Operation(summary = "获取个人工具") @GetMapping - fun get(): ResponseResult> = - ResponseResult.databaseSuccess(ResponseCode.DATABASE_SELECT_SUCCESS, data = editService.get()) + fun get(@Valid pageSortParam: PageSortParam): ResponseResult> = + ResponseResult.databaseSuccess(ResponseCode.DATABASE_SELECT_SUCCESS, data = editService.getPage(pageSortParam)) /** * Get tool detail 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 2fb8321..7cc0da1 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 @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.mapper.tool import com.baomidou.mybatisplus.core.mapper.BaseMapper +import com.baomidou.mybatisplus.core.metadata.IPage import org.apache.ibatis.annotations.Mapper import org.apache.ibatis.annotations.Param import top.fatweb.oxygen.api.entity.tool.Tool @@ -41,15 +42,28 @@ interface EditMapper : BaseMapper { fun selectOne(@Param("id") id: Long, @Param("userId") userId: Long): Tool? /** - * Select tool in list by User ID + * Select tool ID by user ID in page * + * @param page Pagination * @param userId User ID - * @return List of tool object + * @return Tool ID in page + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IPage + */ + fun selectPersonalToolIdPage(page: IPage, @Param("userId") userId: Long): IPage + + /** + * Select tool in list by tool IDs and user ID + * + * @param toolIds List of tool Ids + * @param userId User ID + * @return List of Tool object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see Tool */ - fun selectPersonal(@Param("userId") userId: Long): List + fun selectListByToolIds(@Param("toolIds") toolIds: List, @Param("userId") userId: Long): List /** * Select tool detail diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt index 786f58e..e464b45 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt @@ -29,11 +29,11 @@ interface StoreMapper : BaseMapper { fun selectAuthorToolIdPage(page: IPage, @Param("searchValue") searchValue: String?): IPage /** - * Select tool ID by username in page + * Select author and tool ID by username in page * * @param page Pagination * @param username Username - * @return Tool ID in page + * @return Author:Tool_ID in page * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see IPage @@ -44,7 +44,7 @@ interface StoreMapper : BaseMapper { * Select tool in list by tool IDs * * @param ids List of tool IDs - * @return List of tool object + * @return List of Tool object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see Tool diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt index 69d2d9c..213975b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt @@ -4,5 +4,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper import top.fatweb.oxygen.api.entity.tool.ToolFavorite +/** + * Tool favorite mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseMapper + * @see ToolFavorite + */ @Mapper interface ToolFavoriteMapper : BaseMapper \ No newline at end of file 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 774031c..8d9ba15 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 @@ -3,7 +3,9 @@ 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.entity.tool.ToolBase +import top.fatweb.oxygen.api.param.PageSortParam import top.fatweb.oxygen.api.param.tool.* +import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -98,12 +100,15 @@ interface IEditService : IService { /** * Get personal tools * - * @return List of ToolVo object + * @param pageSortParam Page sort parameters + * @return PageVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see PageSortParam + * @see PageVo * @see ToolVo */ - fun get(): List + fun getPage(pageSortParam: PageSortParam): PageVo /** * Get tool detail diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt index 956d114..d5efaa8 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt @@ -19,16 +19,27 @@ interface IStoreService : IService { /** * Get tool in page * + * @param toolStoreGetParam Get tool parameters in tool store + * @return PageVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see ToolStoreGetParam + * @see PageVo + * @see ToolVo */ - fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo + fun getPage(toolStoreGetParam: ToolStoreGetParam): PageVo /** * Get tool by username in page * + * @param pageSortParam Page sort parameters + * @param username Username + * @return PageVo } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt index 59cf54c..108b50c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt @@ -3,4 +3,12 @@ package top.fatweb.oxygen.api.service.tool import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.oxygen.api.entity.tool.ToolFavorite +/** + * Tool favorite service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IService + * @see ToolFavorite + */ interface IToolFavoriteService : IService \ No newline at end of file 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 d7958f9..d879dbe 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 @@ -2,6 +2,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.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.dao.DuplicateKeyException import org.springframework.stereotype.Service @@ -12,9 +13,11 @@ import top.fatweb.oxygen.api.converter.tool.ToolTemplateConverter import top.fatweb.oxygen.api.entity.tool.* import top.fatweb.oxygen.api.exception.* import top.fatweb.oxygen.api.mapper.tool.EditMapper +import top.fatweb.oxygen.api.param.PageSortParam import top.fatweb.oxygen.api.param.tool.* import top.fatweb.oxygen.api.service.tool.* import top.fatweb.oxygen.api.util.WebUtil +import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -210,9 +213,18 @@ class EditServiceImpl( return this.getOne(tool.id!!) } - override fun get(): List = - baseMapper.selectPersonal(WebUtil.getLoginUserId()!!) - .map(ToolConverter::toolToToolVo) + override fun getPage(pageSortParam: PageSortParam): PageVo { + val toolIdsPage = Page(pageSortParam.currentPage, 20) + toolIdsPage.setOptimizeCountSql(false) + + val toolIdsIPage = baseMapper.selectPersonalToolIdPage(toolIdsPage, WebUtil.getLoginUserId()!!) + val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) + if (toolIdsIPage.total > 0) { + toolPage.setRecords(baseMapper.selectListByToolIds(toolIdsIPage.records, WebUtil.getLoginUserId()!!)) + } + + return ToolConverter.toolPageToToolPageVo(toolPage) + } override fun detail(username: String, toolId: String, ver: String, platform: ToolBase.Platform): ToolVo { if (username == "!" && WebUtil.getLoginUserId() == null) { @@ -272,7 +284,12 @@ class EditServiceImpl( throw RecordAlreadyExists() } - this.detail(toolFavoriteAddParam.username!!, toolFavoriteAddParam.toolId!!, "latest", toolFavoriteAddParam.platform!!) + this.detail( + toolFavoriteAddParam.username!!, + toolFavoriteAddParam.toolId!!, + "latest", + toolFavoriteAddParam.platform!! + ) toolFavoriteService.save( ToolFavorite().apply { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt index 747526f..21e5413 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt @@ -25,11 +25,11 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo */ @Service class StoreServiceImpl : ServiceImpl(), IStoreService { - override fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo { - val toolIdsPage = Page(toolStoreGetParam?.currentPage ?: 1, 20) + override fun getPage(toolStoreGetParam: ToolStoreGetParam): PageVo { + val toolIdsPage = Page(toolStoreGetParam.currentPage, 20) toolIdsPage.setOptimizeCountSql(false) - val toolIdsIPage = baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam?.searchValue) + val toolIdsIPage = baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam.searchValue) val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) if (toolIdsIPage.total > 0) { toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records, WebUtil.getLoginUserId())) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt index 7ac062a..8bb5b55 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt @@ -6,5 +6,15 @@ import top.fatweb.oxygen.api.entity.tool.ToolFavorite import top.fatweb.oxygen.api.mapper.tool.ToolFavoriteMapper import top.fatweb.oxygen.api.service.tool.IToolFavoriteService +/** + * Tool favorite service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see ToolFavoriteMapper + * @see ToolFavorite + * @see IToolFavoriteService + */ @Service class ToolFavoriteServiceImpl : ServiceImpl(), IToolFavoriteService \ No newline at end of file diff --git a/src/main/resources/mapper/tool/EditMapper.xml b/src/main/resources/mapper/tool/EditMapper.xml index c48c967..818ca35 100644 --- a/src/main/resources/mapper/tool/EditMapper.xml +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -94,7 +94,15 @@ and t_b_tool_main.id = #{id} - + select distinct t_b_tool_main.tool_id + from t_b_tool_main + where t_b_tool_main.deleted = 0 + and t_b_tool_main.author_id = #{userId} + order by t_b_tool_main.id desc + + + - - + + \ No newline at end of file -- 2.49.1