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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user