From d50715f58c8f03c170c3a9241ffdad7b2fcc4f50 Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Thu, 6 Jul 2023 23:37:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=BA=86=E6=8C=89?= =?UTF-8?q?=E7=B1=BB=E6=9F=A5=E6=89=BE=E7=9F=A5=E8=AF=86=E5=92=8C=E8=AF=A6?= =?UTF-8?q?=E7=BB=86=E7=9F=A5=E8=AF=86=E7=9A=84=E6=8E=A5=E5=8F=A3=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=80=E4=BA=9Bbug=20fix=20list?= =?UTF-8?q?=EF=BC=9A=20-=20getKnowledgeBrief=E4=B8=8D=E4=BC=9A=E7=AD=9B?= =?UTF-8?q?=E9=80=89null=E7=88=B6=E8=8A=82=E7=82=B9=20-=20createNewKnowled?= =?UTF-8?q?geFolder=E6=97=A0=E6=B3=95=E5=B7=A5=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../knowledge/controller/KnowledgeController.kt | 14 ++++++++++++++ .../cn/edu/hfut/auto/knowledge/entity/Knowledge.kt | 4 ++++ .../knowledge/entity/KnowledgeFileAttribute.kt | 10 +++++++--- .../cn/edu/hfut/auto/knowledge/entity/Note.kt | 11 +++++++++++ .../cn/edu/hfut/auto/knowledge/entity/Tag.kt | 7 +++++++ 5 files changed, 43 insertions(+), 3 deletions(-) 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