diff --git a/src/main/kotlin/cn/edu/hfut/auto/knowledge/controller/KnowledgeController.kt b/src/main/kotlin/cn/edu/hfut/auto/knowledge/controller/KnowledgeController.kt index c5cbb2d..abc7e1d 100644 --- a/src/main/kotlin/cn/edu/hfut/auto/knowledge/controller/KnowledgeController.kt +++ b/src/main/kotlin/cn/edu/hfut/auto/knowledge/controller/KnowledgeController.kt @@ -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") diff --git a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Knowledge.kt b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Knowledge.kt index 55ba131..b8b695d 100644 --- a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Knowledge.kt +++ b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Knowledge.kt @@ -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() diff --git a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/KnowledgeFileAttribute.kt b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/KnowledgeFileAttribute.kt index 41c8c6a..d87ab04 100644 --- a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/KnowledgeFileAttribute.kt +++ b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/KnowledgeFileAttribute.kt @@ -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) } } diff --git a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Note.kt b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Note.kt index 8c816e9..1c9c080 100644 --- a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Note.kt +++ b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Note.kt @@ -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 + + companion object { + val BRIEF_FETCHER = newFetcher(Note::class).by { + allScalarFields() + author(User.BRIEF_FETCHER) + tags(Tag.ALL_FETCHER) + starers() + likers() + } + } } \ No newline at end of file diff --git a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Tag.kt b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Tag.kt index 88e3d4b..60f0140 100644 --- a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Tag.kt +++ b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Tag.kt @@ -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() + } + } } \ No newline at end of file