Add tool detail api
This commit is contained in:
@@ -79,6 +79,7 @@ class SecurityConfig(
|
||||
"/forget",
|
||||
"/retrieve"
|
||||
).anonymous()
|
||||
.requestMatchers("/tool/detail/**").permitAll()
|
||||
// Authentication required
|
||||
.anyRequest().authenticated()
|
||||
}
|
||||
|
||||
@@ -78,4 +78,29 @@ class EditController(
|
||||
@PostMapping
|
||||
fun create(@RequestBody @Valid toolCreateParam: ToolCreateParam): ResponseResult<ToolVo> =
|
||||
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<List<ToolVo>> =
|
||||
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)
|
||||
)
|
||||
}
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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)"
|
||||
}
|
||||
}
|
||||
@@ -19,4 +19,13 @@ interface EditMapper : BaseMapper<Tool> {
|
||||
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<Tool>
|
||||
|
||||
fun detail(
|
||||
@Param("username") username: String,
|
||||
@Param("toolId") toolId: String,
|
||||
@Param("ver") ver: String,
|
||||
@Param("operator") operator: String?
|
||||
): Tool?
|
||||
}
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -71,4 +71,20 @@ interface IEditService : IService<Tool> {
|
||||
* @since 1.0.0
|
||||
*/
|
||||
fun update(toolUpdateParam: ToolUpdateParam): ToolVo
|
||||
|
||||
/**
|
||||
* Get personal tools
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
fun get(): List<ToolVo>
|
||||
|
||||
/**
|
||||
* Get tool detail
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
fun detail(username: String, toolId: String, ver: String): ToolVo
|
||||
}
|
||||
@@ -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<ToolVo> =
|
||||
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()
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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 '工具-主表';
|
||||
@@ -30,7 +30,7 @@
|
||||
and t_b_tool_template.id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectOne" resultMap="toolMap">
|
||||
<select id="selectOne" resultMap="toolWithDataMap">
|
||||
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}
|
||||
</select>
|
||||
|
||||
<select id="selectPersonal" resultMap="toolMap">
|
||||
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,
|
||||
t_b_tool_main.icon as tool_icon,
|
||||
t_b_tool_main.description as tool_description,
|
||||
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.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.create_time as tool_create_time,
|
||||
t_b_tool_main.update_time as tool_update_time,
|
||||
t_b_tool_main.deleted as tool_deleted,
|
||||
t_b_tool_main.version as tool_version,
|
||||
tbtc.id as tool_category_id,
|
||||
tbtc.name as tool_category_name,
|
||||
tbtc.enable as tool_category_enable,
|
||||
tbtc.create_time as tool_category_create_time,
|
||||
tbtc.update_time as tool_category_update_time,
|
||||
tbtc.deleted as tool_category_deleted,
|
||||
tbtc.version as tool_category_version
|
||||
from t_b_tool_main
|
||||
left join (select * from t_r_tool_main_category where deleted = 0) as trtmc
|
||||
on t_b_tool_main.id = trtmc.tool_id
|
||||
left join (select * from t_b_tool_category where deleted = 0 and enable = 1) as tbtc
|
||||
on tbtc.id = trtmc.category_id
|
||||
where t_b_tool_main.deleted = 0
|
||||
and t_b_tool_main.author_id = #{userId}
|
||||
order by t_b_tool_main.tool_id desc
|
||||
</select>
|
||||
|
||||
<select id="detail" resultMap="toolWithDataMap">
|
||||
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,
|
||||
t_b_tool_main.icon as tool_icon,
|
||||
t_b_tool_main.description as tool_description,
|
||||
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.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.create_time as tool_create_time,
|
||||
t_b_tool_main.update_time as tool_update_time,
|
||||
t_b_tool_main.deleted as tool_deleted,
|
||||
t_b_tool_main.version as tool_version,
|
||||
tsu.id as user_id,
|
||||
tsu.username as user_username,
|
||||
tsui.id as user_info_id,
|
||||
tsui.nickname as user_info_nickname,
|
||||
tsui.avatar as user_info_avatar,
|
||||
tsui.email as user_info_email,
|
||||
tbtb.name as tool_base_name,
|
||||
tbtb.dist_id as tool_base_dist_id,
|
||||
tbtbd.data as tool_base_dist_data,
|
||||
tbts.data as tool_source_data,
|
||||
tbts.create_time as tool_source_create_time,
|
||||
tbts.update_time as tool_source_update_time,
|
||||
tbts.deleted as tool_source_deleted,
|
||||
tbts.version as tool_source_version,
|
||||
tbtd.data as tool_dist_data,
|
||||
tbtd.create_time as tool_dist_create_time,
|
||||
tbtd.update_time as tool_dist_update_time,
|
||||
tbtd.deleted as tool_dist_deleted,
|
||||
tbtd.version as tool_dist_version,
|
||||
tbtc.id as tool_category_id,
|
||||
tbtc.name as tool_category_name,
|
||||
tbtc.enable as tool_category_enable,
|
||||
tbtc.create_time as tool_category_create_time,
|
||||
tbtc.update_time as tool_category_update_time,
|
||||
tbtc.deleted as tool_category_deleted,
|
||||
tbtc.version as tool_category_version
|
||||
from t_b_tool_main
|
||||
left join (select * from t_s_user where deleted = 0) as tsu on tsu.id = t_b_tool_main.author_id
|
||||
left join (select * from t_s_user_info where deleted = 0) as tsui
|
||||
on tsui.user_id = t_b_tool_main.author_id
|
||||
left join (select * from t_b_tool_base where deleted = 0) as tbtb on tbtb.id = t_b_tool_main.base_id
|
||||
left join (select * from t_b_tool_data where deleted = 0) as tbtbd on tbtbd.id = tbtb.dist_id
|
||||
left join (select * from t_b_tool_data where deleted = 0) as tbts on tbts.id = t_b_tool_main.source_id
|
||||
left join (select * from t_b_tool_data where deleted = 0) as tbtd on tbtd.id = t_b_tool_main.dist_id
|
||||
left join (select * from t_r_tool_main_category where deleted = 0) as trtmc
|
||||
on t_b_tool_main.id = trtmc.tool_id
|
||||
left join (select * from t_b_tool_category where deleted = 0 and enable = 1) as tbtc
|
||||
on tbtc.id = trtmc.category_id
|
||||
<where>
|
||||
and t_b_tool_main.deleted = 0
|
||||
and t_b_tool_main.tool_id = #{toolId}
|
||||
<choose>
|
||||
<when test="operator == null">
|
||||
and tsu.username = #{username}
|
||||
</when>
|
||||
<otherwise>
|
||||
<choose>
|
||||
<when test="username = '!'">
|
||||
and tsu.username = #{operator}
|
||||
<if test="ver != 'latest'">
|
||||
and t_b_tool_main.ver = #{ver}
|
||||
</if>
|
||||
</when>
|
||||
<otherwise>
|
||||
and tsu.username = #{username}
|
||||
</otherwise>
|
||||
</choose>
|
||||
</otherwise>
|
||||
</choose>
|
||||
</where>
|
||||
order by t_b_tool_main.id desc
|
||||
</select>
|
||||
|
||||
<resultMap id="toolTemplateWithBaseDataMap" type="toolTemplate" extends="top.fatweb.oxygen.api.mapper.tool.ToolTemplateMapper.toolTemplateWithDataMap">
|
||||
<association property="base">
|
||||
<id property="id" column="tool_template_base_id"/>
|
||||
@@ -111,18 +227,24 @@
|
||||
<result property="baseId" column="tool_base_id"/>
|
||||
<result property="authorId" column="tool_author_id"/>
|
||||
<result property="ver" column="tool_ver"/>
|
||||
<result property="privately" column="tool_privately"/>
|
||||
<result property="sourceId" column="tool_source_id"/>
|
||||
<result property="distId" column="tool_dist_id"/>
|
||||
<result property="entryPoint" column="tool_entry_point"/>
|
||||
<result property="publish" column="tool_publish"/>
|
||||
<result property="review" column="tool_review"/>
|
||||
<result property="publishTime" column="tool_publish_time"/>
|
||||
<result property="updateTime" column="tool_update_time"/>
|
||||
<result property="createTime" column="tool_create_time"/>
|
||||
<result property="deleted" column="tool_deleted"/>
|
||||
<result property="version" column="tool_version"/>
|
||||
<collection property="keywords" ofType="string" column="tool_keywords"/>
|
||||
<collection property="categories" resultMap="top.fatweb.oxygen.api.mapper.tool.ToolCategoryMapper.toolCategoryMap"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="toolWithAuthor" type="tool" extends="toolMap">
|
||||
<association property="author" resultMap="top.fatweb.oxygen.api.mapper.permission.UserMapper.userWithInfoMap"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="toolWithDataMap" type="tool" extends="toolWithAuthor">
|
||||
<association property="base" resultMap="top.fatweb.oxygen.api.mapper.tool.ToolBaseMapper.toolBaseWithDataMap"/>
|
||||
<association property="source">
|
||||
<id property="id" column="tool_source_id"/>
|
||||
@@ -140,7 +262,5 @@
|
||||
<result property="deleted" column="tool_dist_deleted"/>
|
||||
<result property="version" column="tool_dist_version"/>
|
||||
</association>
|
||||
<collection property="keywords" ofType="string" column="tool_keywords"/>
|
||||
<collection property="categories" resultMap="top.fatweb.oxygen.api.mapper.tool.ToolCategoryMapper.toolCategoryMap"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user