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..86f8d4c 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,10 +8,12 @@ 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.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.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 @@ -113,13 +115,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/controller/tool/StoreController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt index c29e193..f3c1e58 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt @@ -2,12 +2,14 @@ package top.fatweb.oxygen.api.controller.tool import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.* import top.fatweb.oxygen.api.annotation.BaseController 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.param.PageSortParam +import top.fatweb.oxygen.api.param.tool.ToolFavoriteAddParam +import top.fatweb.oxygen.api.param.tool.ToolFavoriteRemoveParam import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam import top.fatweb.oxygen.api.service.tool.IStoreService import top.fatweb.oxygen.api.vo.PageVo @@ -60,4 +62,58 @@ class StoreController( @GetMapping("/{username}") fun get(@PathVariable username: String, @Valid pageSortParam: PageSortParam): ResponseResult> = ResponseResult.databaseSuccess(data = storeService.getPage(pageSortParam, username.trim())) + + /** + * 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 { + storeService.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 { + storeService.removeFavorite(toolFavoriteRemoveParam) + + return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + } + + /** + * Get favorite tool + * + * @param pageSortParam Page sort parameters + * @return Response object includes favorite tool paging information + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see PageSortParam + * @see ResponseResult + * @see PageVo + * @see ToolVo + */ + @Trim + @Operation(summary = "获取收藏工具") + @GetMapping("/favorite") + fun getFavorite(@Valid pageSortParam: PageSortParam): ResponseResult> = + ResponseResult.databaseSuccess(data = storeService.getFavorite(pageSortParam)) } \ 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 6788c81..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 @@ -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 * @@ -246,7 +247,16 @@ class Tool { @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/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/ToolFavorite.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolFavorite.kt new file mode 100644 index 0000000..1d474e6 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolFavorite.kt @@ -0,0 +1,67 @@ +package top.fatweb.oxygen.api.entity.tool + +import com.baomidou.mybatisplus.annotation.* +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 + + /** + * Author ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("author_id") + var authorId: Long? = null + + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("tool_id") + var toolId: String? = 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, authorId=$authorId, toolId=$toolId, deleted=$deleted, version=$version)" + } +} \ No newline at end of file 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 * 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/EditMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt index f874483..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 @@ -69,5 +83,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/mapper/tool/StoreMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt index 78e6449..7efdf91 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,28 +29,17 @@ 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 */ fun selectAuthorToolIdPageByUsername(page: IPage, @Param("username") username: String): IPage - /** - * Select tool in list by tool IDs - * - * @param ids List of tool IDs - * @return List of tool object - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see Tool - */ - fun selectListByIds(@Param("ids") ids: List): List - /** * Select tool in list by Author:Tool_ID * @@ -60,5 +49,16 @@ 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 + + /** + * Count published tool by username and toolId + * + * @param authorId Author ID + * @param toolId Tool ID + * @return Number + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun countPublishedToolByAuthorAndToolId(@Param("authorId") authorId: Long, @Param("toolId") toolId: String): Long } \ 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..213975b --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt @@ -0,0 +1,16 @@ +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 + +/** + * 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/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/ToolFavoriteAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteAddParam.kt new file mode 100644 index 0000000..28b6fc0 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteAddParam.kt @@ -0,0 +1,40 @@ +package top.fatweb.oxygen.api.param.tool + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.Pattern +import top.fatweb.oxygen.api.annotation.Trim + +/** + * Add favorite tool parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +data class ToolFavoriteAddParam( + /** + * Author ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Trim + @Schema(description = "作者 ID", required = true) + @field: NotBlank(message = "AuthorId cannot be blank") + var authorId: Long?, + + /** + * 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? +) \ 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..17741ee --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteRemoveParam.kt @@ -0,0 +1,40 @@ +package top.fatweb.oxygen.api.param.tool + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.Pattern +import top.fatweb.oxygen.api.annotation.Trim + +/** + * Remove favorite tool parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +data class ToolFavoriteRemoveParam( + /** + * Author ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Trim + @Schema(description = "作者 ID", required = true) + @field: NotBlank(message = "AuthorId cannot be blank") + var authorId: Long?, + + /** + * 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?, +) \ No newline at end of file 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?, 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 afdbb73..fdb418c 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 @@ -46,9 +46,15 @@ import java.util.* * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see VelocityEngine * @see AuthenticationManager + * @see PasswordEncoder * @see RedisUtil + * @see TurnstileApi * @see IUserService + * @see IUserInfoService + * @see ISensitiveWordService + * @see IAvatarService * @see IAuthenticationService */ @Service diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RUserRoleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RUserRoleServiceImpl.kt index 86f705c..3a9d0b2 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RUserRoleServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RUserRoleServiceImpl.kt @@ -13,6 +13,7 @@ import top.fatweb.oxygen.api.service.permission.IRUserRoleService * @since 1.0.0 * @see ServiceImpl * @see RUserRoleMapper + * @see RUserRole * @see IRUserRoleService */ @Service diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserDetailsServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserDetailsServiceImpl.kt index 95a3498..ad82c48 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserDetailsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserDetailsServiceImpl.kt @@ -16,7 +16,9 @@ import top.fatweb.oxygen.api.service.permission.IUserService * @see UserDetailsService */ @Service -class UserDetailsServiceImpl(val userService: IUserService) : UserDetailsService { +class UserDetailsServiceImpl( + private val userService: IUserService +) : UserDetailsService { override fun loadUserByUsername(account: String): UserDetails { val user = userService.getUserWithPowerByAccount(account) user ?: throw UserNotFoundException() diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserInfoServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserInfoServiceImpl.kt index c9ceb1e..2e92d4b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserInfoServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserInfoServiceImpl.kt @@ -13,6 +13,7 @@ import top.fatweb.oxygen.api.service.permission.IUserInfoService * @since 1.0.0 * @see ServiceImpl * @see UserInfoMapper + * @see UserInfo * @see IUserInfoService */ @Service diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/EventLogServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/EventLogServiceImpl.kt index b2d51d6..37ff2df 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/EventLogServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/EventLogServiceImpl.kt @@ -17,6 +17,10 @@ import top.fatweb.oxygen.api.service.system.IEventLogService * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see ServiceImpl + * @see EventLogMapper + * @see EventLog + * @see IEventLogService */ @DS("sqlite") @Service diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt index e973d23..f60c2f0 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt @@ -20,6 +20,10 @@ import top.fatweb.oxygen.api.vo.system.SensitiveWordVo * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see ServiceImpl + * @see SensitiveWordMapper + * @see SensitiveWord + * @see ISensitiveWordService */ @Service class SensitiveWordServiceImpl : ServiceImpl(), ISensitiveWordService { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsLogServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsLogServiceImpl.kt index b7faec6..1c3f1c8 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsLogServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsLogServiceImpl.kt @@ -12,6 +12,10 @@ import top.fatweb.oxygen.api.service.system.IStatisticsLogService * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see ServiceImpl + * @see StatisticsLogMapper + * @see StatisticsLog + * @see IStatisticsLogService */ @DS("sqlite") @Service diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsServiceImpl.kt index ae264a7..a5f936e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsServiceImpl.kt @@ -29,6 +29,10 @@ import java.util.concurrent.TimeUnit * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see RedisUtil + * @see IStatisticsLogService + * @see IEventLogService + * @see IStatisticsService */ @Service class StatisticsServiceImpl( 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..e9b64bc 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,11 @@ 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.ToolCreateParam import top.fatweb.oxygen.api.param.tool.ToolUpdateParam import top.fatweb.oxygen.api.param.tool.ToolUpgradeParam +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 @@ -100,12 +102,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..f5a3337 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 @@ -3,6 +3,8 @@ 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.PageSortParam +import top.fatweb.oxygen.api.param.tool.ToolFavoriteAddParam +import top.fatweb.oxygen.api.param.tool.ToolFavoriteRemoveParam import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -19,16 +21,60 @@ 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 + + /*** + * 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) + + /** + * Get favorite tool + * + * @param pageSortParam Page sort parameters + * @return PageVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see PageSortParam + * @see PageVo + * @see ToolVo + */ + fun getFavorite(pageSortParam: PageSortParam): 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 new file mode 100644 index 0000000..108b50c --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt @@ -0,0 +1,14 @@ +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 44165cb..74e2208 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,11 +13,13 @@ 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.ToolCreateParam import top.fatweb.oxygen.api.param.tool.ToolUpdateParam import top.fatweb.oxygen.api.param.tool.ToolUpgradeParam 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 @@ -211,20 +214,26 @@ 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) { 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/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt index 96ac255..4810eae 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 @@ -29,6 +29,8 @@ import java.time.ZoneOffset * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see IToolDataService + * @see IRToolCategoryService * @see ServiceImpl * @see ManagementMapper * @see Tool @@ -123,5 +125,4 @@ class ManagementServiceImpl( return this.removeById(id) } - } \ 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..18fb21a 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 @@ -1,14 +1,23 @@ package top.fatweb.oxygen.api.service.tool.impl +import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.tool.ToolConverter import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.entity.tool.ToolFavorite +import top.fatweb.oxygen.api.exception.NoRecordFoundException +import top.fatweb.oxygen.api.exception.RecordAlreadyExists import top.fatweb.oxygen.api.mapper.tool.StoreMapper import top.fatweb.oxygen.api.param.PageSortParam +import top.fatweb.oxygen.api.param.tool.ToolFavoriteAddParam +import top.fatweb.oxygen.api.param.tool.ToolFavoriteRemoveParam import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam import top.fatweb.oxygen.api.service.tool.IStoreService +import top.fatweb.oxygen.api.service.tool.IToolFavoriteService +import top.fatweb.oxygen.api.util.WebUtil import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -23,15 +32,17 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo * @see IStoreService */ @Service -class StoreServiceImpl : ServiceImpl(), IStoreService { - override fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo { - val toolIdsPage = Page(toolStoreGetParam?.currentPage ?: 1, 20) +class StoreServiceImpl( + private val toolFavoriteService: IToolFavoriteService +) : ServiceImpl(), IStoreService { + 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)) + toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records, WebUtil.getLoginUserId())) } return ToolConverter.toolPageToToolPageVo(toolPage) @@ -44,7 +55,74 @@ 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) + } + + @Transactional + override fun addFavorite(toolFavoriteAddParam: ToolFavoriteAddParam) { + if (toolFavoriteAddParam.authorId == WebUtil.getLoginUserId()) { + throw NoRecordFoundException() + } + + if (toolFavoriteService.exists( + KtQueryWrapper(ToolFavorite()) + .eq(ToolFavorite::userId, WebUtil.getLoginUserId()) + .eq(ToolFavorite::authorId, toolFavoriteAddParam.authorId) + .eq(ToolFavorite::toolId, toolFavoriteAddParam.toolId) + ) + ) { + throw RecordAlreadyExists() + } + + if (baseMapper.countPublishedToolByAuthorAndToolId( + toolFavoriteAddParam.authorId!!, + toolFavoriteAddParam.toolId!! + ) <= 0 + ) { + throw NoRecordFoundException() + } + + toolFavoriteService.save( + ToolFavorite().apply { + userId = WebUtil.getLoginUserId() + authorId = toolFavoriteAddParam.authorId + toolId = toolFavoriteAddParam.toolId + } + ) + } + + @Transactional + override fun removeFavorite(toolFavoriteRemoveParam: ToolFavoriteRemoveParam) { + if (!toolFavoriteService.remove( + KtQueryWrapper(ToolFavorite()) + .eq(ToolFavorite::userId, WebUtil.getLoginUserId()) + .eq(ToolFavorite::authorId, toolFavoriteRemoveParam.authorId) + .eq(ToolFavorite::toolId, toolFavoriteRemoveParam.toolId) + ) + ) { + throw NoRecordFoundException() + } + } + + override fun getFavorite(pageSortParam: PageSortParam): PageVo { + val toolFavoritePage = Page(pageSortParam.currentPage, 20) + + val toolFavoriteIPage = toolFavoriteService.page( + toolFavoritePage, + KtQueryWrapper(ToolFavorite()).eq(ToolFavorite::userId, WebUtil.getLoginUserId()) + ) + + val toolPage = Page(toolFavoriteIPage.current, toolFavoriteIPage.size, toolFavoriteIPage.total) + if (toolFavoriteIPage.total > 0) { + toolPage.setRecords( + baseMapper.selectListByAuthorToolIds( + toolFavoriteIPage.records.map { "${it.authorId}:${it.toolId}" }, + WebUtil.getLoginUserId() + ) + ) } return ToolConverter.toolPageToToolPageVo(toolPage) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt index fc2fb9d..237ba10 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt @@ -24,6 +24,7 @@ import top.fatweb.oxygen.api.vo.tool.ToolBaseVo * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see IToolDataService * @see ServiceImpl * @see ToolBaseMapper * @see ToolBase 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..8bb5b55 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt @@ -0,0 +1,20 @@ +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 + +/** + * 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/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt index 45ee0ae..34195b9 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt @@ -24,6 +24,8 @@ import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see IToolDataService + * @see IToolBaseService * @see ServiceImpl * @see ToolTemplateMapper * @see ToolTemplate 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..6eded91 --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_240426__Add_table_'t_b_tool_favorite'.sql @@ -0,0 +1,12 @@ +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', + author_id bigint not null comment '作者 ID', + tool_id varchar(50) not null comment '工具 ID', + 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, author_id, tool_id, deleted) +) comment '工具-收藏表'; \ 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 ca46957..b7ad444 100644 --- a/src/main/resources/mapper/tool/EditMapper.xml +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -94,7 +94,19 @@ and t_b_tool_main.id = #{id} - + select t.tool_id + from (select tbtm.tool_id + from (select *, + row_number() over (partition by t_b_tool_main.tool_id order by t_b_tool_main.id desc ) as rn + from t_b_tool_main + where t_b_tool_main.deleted = 0 + and t_b_tool_main.author_id = #{userId}) tbtm + where tbtm.rn = 1 + order by tbtm.id desc) t + + + \ 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 temp1.publish != 0 and temp1.review = 'PASS' and ( temp1.name like concat('%', #{searchValue}, '%') @@ -45,70 +45,18 @@ 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 - - + + \ No newline at end of file diff --git a/src/main/resources/mapper/tool/ToolFavoriteMapper.xml b/src/main/resources/mapper/tool/ToolFavoriteMapper.xml new file mode 100644 index 0000000..9c98dda --- /dev/null +++ b/src/main/resources/mapper/tool/ToolFavoriteMapper.xml @@ -0,0 +1,10 @@ + + + + + + + + + +