diff --git a/src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt index 5d59bfe..3c0059b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt @@ -79,6 +79,7 @@ class SecurityConfig( "/forget", "/retrieve" ).anonymous() + .requestMatchers("/tool/detail/**").permitAll() // Authentication required .anyRequest().authenticated() } 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 1e735e6..af6335f 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 @@ -78,4 +78,29 @@ class EditController( @PostMapping fun create(@RequestBody @Valid toolCreateParam: ToolCreateParam): ResponseResult = ResponseResult.databaseSuccess(ResponseCode.DATABASE_INSERT_SUCCESS, data = editService.create(toolCreateParam)) + + /** + * Get personal tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "获取个人工具") + @GetMapping + fun get(): ResponseResult> = + ResponseResult.databaseSuccess(ResponseCode.DATABASE_SELECT_SUCCESS, data = editService.get()) + + /** + * Get tool detail + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "获取工具内容") + @GetMapping("/detail/{username}/{toolId}/{ver}") + fun detail(@PathVariable username: String, @PathVariable toolId: String, @PathVariable ver: String) = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_SELECT_SUCCESS, + data = editService.detail(username, toolId, ver) + ) } \ 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 bed4354..9c9c39d 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 @@ -27,18 +27,16 @@ object ToolConverter { toolId = tool.toolId, icon = tool.icon, description = tool.description, - baseId = tool.baseId, + base = tool.base?.let(ToolBaseConverter::toolBaseToToolBaseVo), author = tool.author?.let(UserConverter::userToUserWithInfoVo), ver = tool.ver, - privately = tool.privately == 1, keywords = tool.keywords, categories = tool.categories?.map(ToolCategoryConverter::toolCategoryToToolCategoryVo), source = tool.source?.let(ToolDataConverter::toolDataToToolDataVo), dist = tool.dist?.let(ToolDataConverter::toolDataToToolDataVo), entryPoint = tool.entryPoint, - publish = tool.publish == 1, + publish = tool.publish, review = tool.review, - publishTime = tool.publishTime, createTime = tool.createTime, updateTime = tool.updateTime ) 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 7c61490..ae485ff 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 @@ -96,15 +96,6 @@ class Tool { @TableField("ver") var ver: String? = null - /** - * Privately - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @TableField("privately") - var privately: Int? = null - /** * Keywords * @@ -148,7 +139,7 @@ class Tool { * @since 1.0.0 */ @TableField("publish") - var publish: Int? = null + var publish: Long? = null /** * Review @@ -160,16 +151,6 @@ class Tool { @TableField("review") var review: ReviewType? = null - /** - * Publish time - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see LocalDateTime - */ - @TableField("publish_time") - var publishTime: LocalDateTime? = null - /** * Create time * @@ -256,6 +237,6 @@ class Tool { var dist: ToolData? = null override fun toString(): String { - return "Tool(id=$id, name=$name, toolId=$toolId, icon=$icon, description=$description, baseId=$baseId, authorId=$authorId, ver=$ver, privately=$privately, keywords=$keywords, sourceId=$sourceId, distId=$distId, entryPoint=$entryPoint, publish=$publish, review=$review, publishTime=$publishTime, 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, 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)" } } \ No newline at end of file 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 56f0802..567f741 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 @@ -19,4 +19,13 @@ interface EditMapper : BaseMapper { fun getTemplate(@Param("id") id: Long): ToolTemplate? fun selectOne(@Param("id") id: Long, @Param("userId") userId: Long): Tool? + + fun selectPersonal(@Param("userId") userId: Long): List + + fun detail( + @Param("username") username: String, + @Param("toolId") toolId: String, + @Param("ver") ver: String, + @Param("operator") operator: String? + ): Tool? } \ 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 1955b93..8cd4e83 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 @@ -78,15 +78,6 @@ data class ToolCreateParam( @field: NotNull(message = "TemplateId can not be null") val templateId: Long?, - /** - * Privately - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "私有", allowableValues = ["true", "false"], defaultValue = "false") - val privately: Boolean = false, - /** * Keywords * 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 819fc66..b8717ea 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 @@ -71,4 +71,20 @@ interface IEditService : IService { * @since 1.0.0 */ fun update(toolUpdateParam: ToolUpdateParam): ToolVo + + /** + * Get personal tools + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun get(): List + + /** + * Get tool detail + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun detail(username: String, toolId: String, ver: String): ToolVo } \ 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 434abf8..58c0a4b 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 @@ -67,7 +67,6 @@ class EditServiceImpl( baseId = template.base!!.id authorId = WebUtil.getLoginUserId() ?: throw UserNotFoundException() ver = toolCreateParam.ver!!.split(".").map(String::toLong).joinToString(".") - privately = if (toolCreateParam.privately) 1 else 0 keywords = toolCreateParam.keywords sourceId = newSource.id distId = newDist.id @@ -90,4 +89,17 @@ class EditServiceImpl( override fun update(toolUpdateParam: ToolUpdateParam): ToolVo { TODO("Not yet implemented") } + + override fun get(): List = + baseMapper.selectPersonal(WebUtil.getLoginUserId() ?: throw UserNotFoundException()) + .map(ToolConverter::toolToToolVo) + + override fun detail(username: String, toolId: String, ver: String): ToolVo { + if (username == "!" && WebUtil.getLoginUserId() == null) { + throw NoRecordFoundException() + } + + return baseMapper.detail(username, toolId, ver, WebUtil.getLoginUsername())?.let(ToolConverter::toolToToolVo) + ?: throw NoRecordFoundException() + } } \ 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 8569307..5a32d44 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 @@ -60,14 +60,13 @@ data class ToolVo( val description: String?, /** - * Base ID + * Base * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @JsonSerialize(using = ToStringSerializer::class) - @Schema(description = "基板 ID") - val baseId: Long?, + @Schema(description = "基板") + val base: ToolBaseVo?, /** * Author @@ -88,15 +87,6 @@ data class ToolVo( @Schema(description = "版本") val ver: String?, - /** - * Privately - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "私有") - val privately: Boolean?, - /** * Keywords * @@ -151,8 +141,9 @@ data class ToolVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @JsonSerialize(using = ToStringSerializer::class) @Schema(description = "发布") - val publish: Boolean?, + val publish: Long?, /** * Review @@ -164,16 +155,6 @@ data class ToolVo( @Schema(description = "审核") val review: Tool.ReviewType?, - /** - * Publish time - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see LocalDateTime - */ - @Schema(description = "发布时间", example = "1900-01-01T00:00:00.000Z") - val publishTime: LocalDateTime?, - /** * Create time * diff --git a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql index 39ba7c4..1b396f2 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql @@ -2,25 +2,24 @@ drop table if exists t_b_tool_main; create table if not exists t_b_tool_main ( - id bigint not null primary key, - name varchar(50) not null comment '工具名', - tool_id varchar(50) not null comment '工具 ID', - icon text not null comment '图标', - description varchar(500) null comment '简介', - base_id bigint not null comment '基板 ID', - author_id bigint not null comment '作者 ID', - ver varchar(20) not null comment '版本', - privately int not null default 0 comment '私有', - keywords varchar(500) not null comment '关键字', - source_id bigint not null comment '源码 ID', - dist_id bigint not null comment '产物 ID', - entry_point varchar(64) not null default 'main.tsx' comment '入口文件', - publish int not null default 0 comment '发布', - review varchar(10) not null default 'NONE' comment '审核', - publish_time datetime null comment '发布时间', - create_time datetime not null default (utc_timestamp()) comment '创建时间', - update_time datetime not null default (utc_timestamp()) comment '修改时间', - deleted bigint not null default 0, - version int not null default 0, - constraint t_b_tool_main_unique_tool_id unique (tool_id, author_id, ver, deleted) + id bigint not null primary key, + name varchar(50) not null comment '工具名', + tool_id varchar(50) not null comment '工具 ID', + icon text not null comment '图标', + description varchar(500) null comment '简介', + base_id bigint not null comment '基板 ID', + author_id bigint not null comment '作者 ID', + ver varchar(20) not null comment '版本', + keywords varchar(500) not null comment '关键字', + source_id bigint not null comment '源码 ID', + dist_id bigint not null comment '产物 ID', + entry_point varchar(64) not null default 'main.tsx' comment '入口文件', + publish bigint not null default 0 comment '发布', + review varchar(10) not null default 'NONE' comment '审核', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0, + constraint t_b_tool_main_unique_tool_id_ver unique (tool_id, author_id, ver, deleted), + constraint t_b_tool_main_unique_tool_id_publish unique (tool_id, author_id, publish, 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 f3f1c9f..b8ab555 100644 --- a/src/main/resources/mapper/tool/EditMapper.xml +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -30,7 +30,7 @@ and t_b_tool_template.id = #{id} - select t_b_tool_main.id as tool_id, t_b_tool_main.name as tool_name, t_b_tool_main.tool_id as tool_tool_id, @@ -39,14 +39,12 @@ t_b_tool_main.base_id as tool_base_id, t_b_tool_main.author_id as tool_author_id, t_b_tool_main.ver as tool_ver, - t_b_tool_main.privately as tool_privately, t_b_tool_main.keywords as tool_keywords, t_b_tool_main.source_id as tool_source_id, t_b_tool_main.dist_id as tool_dist_id, t_b_tool_main.entry_point as tool_entry_point, t_b_tool_main.publish as tool_publish, t_b_tool_main.review as tool_review, - t_b_tool_main.publish_time as tool_publish_time, t_b_tool_main.create_time as tool_create_time, t_b_tool_main.update_time as tool_update_time, t_b_tool_main.deleted as tool_deleted, @@ -94,6 +92,124 @@ and t_b_tool_main.id = #{id} + + + + @@ -111,18 +227,24 @@ - - + + + + + + + + @@ -140,7 +262,5 @@ - - \ No newline at end of file