feat: 新增了按类查找知识和详细知识的接口,修复了一些bug
fix list: - getKnowledgeBrief不会筛选null父节点 - createNewKnowledgeFolder无法工作master
parent
9cb228dc5e
commit
d50715f58c
|
@ -48,6 +48,20 @@ class KnowledgeController(
|
|||
return knowledgeRepository.findNullable(knowledgeId, Knowledge.AS_PARENT_FETCHER) ?: throw BusinessError(ErrorCode.RESOURCE_NOT_FOUND)
|
||||
}
|
||||
|
||||
@GetMapping("/{knowledgeId}/detailed")
|
||||
suspend fun getKnowledgeDetailed(@PathVariable knowledgeId: UUID): Knowledge {
|
||||
val knowledge = knowledgeRepository.findNullable(knowledgeId, Knowledge.DETAILED_FILE_FETCHER)
|
||||
?: throw BusinessError(ErrorCode.RESOURCE_NOT_FOUND)
|
||||
val knowledgeFileAttribute = knowledge.knowledgeFileAttribute ?: throw BusinessError(ErrorCode.RESOURCE_NOT_FOUND)
|
||||
knowledgeRepository.update(new(Knowledge::class).by {
|
||||
id = knowledge.id
|
||||
knowledgeFileAttribute().apply {
|
||||
pageView = knowledgeFileAttribute.pageView + 1
|
||||
}
|
||||
})
|
||||
return knowledge
|
||||
}
|
||||
|
||||
@SaCheckRole("1")
|
||||
@Transactional(rollbackFor = [Throwable::class])
|
||||
@PostMapping("/file")
|
||||
|
|
|
@ -30,6 +30,10 @@ interface Knowledge {
|
|||
allScalarFields()
|
||||
knowledgeFileAttribute(KnowledgeFileAttribute.BRIEF_FETCHER)
|
||||
}
|
||||
val DETAILED_FILE_FETCHER = newFetcher(Knowledge::class).by {
|
||||
allScalarFields()
|
||||
knowledgeFileAttribute(KnowledgeFileAttribute.DETAILED_FETCHER)
|
||||
}
|
||||
val AS_PARENT_FETCHER = newFetcher(Knowledge::class).by {
|
||||
allScalarFields()
|
||||
parent()
|
||||
|
|
|
@ -34,9 +34,13 @@ interface KnowledgeFileAttribute {
|
|||
val EXTERNAL_PREVIEWABLE_SUFFIXES = listOf("pdf", "ppt", "pptx", "doc", "docx", "xls", "xlsx")
|
||||
val BRIEF_FETCHER = newFetcher(KnowledgeFileAttribute::class).by {
|
||||
allScalarFields()
|
||||
tags {
|
||||
allScalarFields()
|
||||
tags(Tag.ALL_FETCHER)
|
||||
}
|
||||
val DETAILED_FETCHER = newFetcher(KnowledgeFileAttribute::class).by {
|
||||
allScalarFields()
|
||||
starers()
|
||||
notes(Note.BRIEF_FETCHER)
|
||||
tags(Tag.ALL_FETCHER)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.edu.hfut.auto.knowledge.entity
|
||||
|
||||
import org.babyfish.jimmer.sql.*
|
||||
import org.babyfish.jimmer.sql.kt.fetcher.newFetcher
|
||||
import org.babyfish.jimmer.sql.meta.UUIDIdGenerator
|
||||
import java.time.LocalDateTime
|
||||
import java.util.*
|
||||
|
@ -36,4 +37,14 @@ interface Note {
|
|||
@ManyToMany
|
||||
@JoinTable(name = "note_liker_mapping")
|
||||
val likers: List<User>
|
||||
|
||||
companion object {
|
||||
val BRIEF_FETCHER = newFetcher(Note::class).by {
|
||||
allScalarFields()
|
||||
author(User.BRIEF_FETCHER)
|
||||
tags(Tag.ALL_FETCHER)
|
||||
starers()
|
||||
likers()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import org.babyfish.jimmer.sql.Entity
|
|||
import org.babyfish.jimmer.sql.GeneratedValue
|
||||
import org.babyfish.jimmer.sql.GenerationType
|
||||
import org.babyfish.jimmer.sql.Id
|
||||
import org.babyfish.jimmer.sql.kt.fetcher.newFetcher
|
||||
|
||||
@Entity
|
||||
interface Tag {
|
||||
|
@ -11,4 +12,10 @@ interface Tag {
|
|||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
val id: Long
|
||||
val name: String
|
||||
|
||||
companion object {
|
||||
val ALL_FETCHER = newFetcher(Tag::class).by {
|
||||
allScalarFields()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue