From 2a32f0052814227a136e0e967dba8c685ccb656b Mon Sep 17 00:00:00 2001 From: fuzui <73400@163.com> Date: Sat, 26 Feb 2022 21:42:16 +0800 Subject: [PATCH 1/2] fix: Post and sheet content is empty in the Content API --- .../app/controller/content/api/PostController.java | 11 +++++++++-- .../app/controller/content/api/SheetController.java | 9 +++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/run/halo/app/controller/content/api/PostController.java b/src/main/java/run/halo/app/controller/content/api/PostController.java index 2ca313eecf..930afadee6 100644 --- a/src/main/java/run/halo/app/controller/content/api/PostController.java +++ b/src/main/java/run/halo/app/controller/content/api/PostController.java @@ -25,6 +25,7 @@ import run.halo.app.exception.NotFoundException; import run.halo.app.model.dto.BaseCommentDTO; import run.halo.app.model.dto.post.BasePostSimpleDTO; +import run.halo.app.model.entity.Content; import run.halo.app.model.entity.Post; import run.halo.app.model.entity.PostComment; import run.halo.app.model.enums.CommentStatus; @@ -105,7 +106,9 @@ public PostDetailVO getBy(@PathVariable("postId") Integer postId, Boolean formatDisabled, @RequestParam(value = "sourceDisabled", required = false, defaultValue = "false") Boolean sourceDisabled) { - PostDetailVO postDetailVO = postService.convertToDetailVo(postService.getById(postId)); + Post post = postService.getById(postId); + post.setContent(Content.PatchedContent.of(postService.getContentById(postId))); + PostDetailVO postDetailVO = postService.convertToDetailVo(post); if (formatDisabled) { // Clear the format content @@ -129,7 +132,9 @@ public PostDetailVO getBy(@RequestParam("slug") String slug, Boolean formatDisabled, @RequestParam(value = "sourceDisabled", required = false, defaultValue = "false") Boolean sourceDisabled) { - PostDetailVO postDetailVO = postService.convertToDetailVo(postService.getBySlug(slug)); + Post post = postService.getBySlug(slug); + post.setContent(Content.PatchedContent.of(postService.getContentById(post.getId()))); + PostDetailVO postDetailVO = postService.convertToDetailVo(post); if (formatDisabled) { // Clear the format content @@ -152,6 +157,7 @@ public PostDetailVO getPrevPostBy(@PathVariable("postId") Integer postId) { Post post = postService.getById(postId); Post prevPost = postService.getPrevPost(post).orElseThrow(() -> new NotFoundException("查询不到该文章的信息")); + prevPost.setContent(Content.PatchedContent.of(postService.getContentById(prevPost.getId()))); return postService.convertToDetailVo(prevPost); } @@ -161,6 +167,7 @@ public PostDetailVO getNextPostBy(@PathVariable("postId") Integer postId) { Post post = postService.getById(postId); Post nextPost = postService.getNextPost(post).orElseThrow(() -> new NotFoundException("查询不到该文章的信息")); + nextPost.setContent(Content.PatchedContent.of(postService.getContentById(nextPost.getId()))); return postService.convertToDetailVo(nextPost); } diff --git a/src/main/java/run/halo/app/controller/content/api/SheetController.java b/src/main/java/run/halo/app/controller/content/api/SheetController.java index c8b959d71b..b5f01aef70 100644 --- a/src/main/java/run/halo/app/controller/content/api/SheetController.java +++ b/src/main/java/run/halo/app/controller/content/api/SheetController.java @@ -21,6 +21,7 @@ import org.springframework.web.util.HtmlUtils; import run.halo.app.cache.lock.CacheLock; import run.halo.app.model.dto.BaseCommentDTO; +import run.halo.app.model.entity.Content; import run.halo.app.model.entity.Sheet; import run.halo.app.model.entity.SheetComment; import run.halo.app.model.enums.CommentStatus; @@ -74,7 +75,9 @@ public SheetDetailVO getBy(@PathVariable("sheetId") Integer sheetId, Boolean formatDisabled, @RequestParam(value = "sourceDisabled", required = false, defaultValue = "false") Boolean sourceDisabled) { - SheetDetailVO sheetDetailVO = sheetService.convertToDetailVo(sheetService.getById(sheetId)); + Sheet sheet = sheetService.getById(sheetId); + sheet.setContent(Content.PatchedContent.of(sheetService.getContentById(sheetId))); + SheetDetailVO sheetDetailVO = sheetService.convertToDetailVo(sheet); if (formatDisabled) { // Clear the format content @@ -98,7 +101,9 @@ public SheetDetailVO getBy(@RequestParam("slug") String slug, Boolean formatDisabled, @RequestParam(value = "sourceDisabled", required = false, defaultValue = "false") Boolean sourceDisabled) { - SheetDetailVO sheetDetailVO = sheetService.convertToDetailVo(sheetService.getBySlug(slug)); + Sheet sheet = sheetService.getBySlug(slug); + sheet.setContent(Content.PatchedContent.of(sheetService.getContentById(sheet.getId()))); + SheetDetailVO sheetDetailVO = sheetService.convertToDetailVo(sheet); if (formatDisabled) { // Clear the format content From fdf90a4c95df662b7dfebd4dbf859192411f5f77 Mon Sep 17 00:00:00 2001 From: fuzui <73400@163.com> Date: Sat, 26 Feb 2022 23:10:41 +0800 Subject: [PATCH 2/2] style: Format PostController.java --- .../run/halo/app/controller/content/api/PostController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/run/halo/app/controller/content/api/PostController.java b/src/main/java/run/halo/app/controller/content/api/PostController.java index 930afadee6..bafed62c04 100644 --- a/src/main/java/run/halo/app/controller/content/api/PostController.java +++ b/src/main/java/run/halo/app/controller/content/api/PostController.java @@ -157,7 +157,8 @@ public PostDetailVO getPrevPostBy(@PathVariable("postId") Integer postId) { Post post = postService.getById(postId); Post prevPost = postService.getPrevPost(post).orElseThrow(() -> new NotFoundException("查询不到该文章的信息")); - prevPost.setContent(Content.PatchedContent.of(postService.getContentById(prevPost.getId()))); + prevPost.setContent( + Content.PatchedContent.of(postService.getContentById(prevPost.getId()))); return postService.convertToDetailVo(prevPost); } @@ -167,7 +168,8 @@ public PostDetailVO getNextPostBy(@PathVariable("postId") Integer postId) { Post post = postService.getById(postId); Post nextPost = postService.getNextPost(post).orElseThrow(() -> new NotFoundException("查询不到该文章的信息")); - nextPost.setContent(Content.PatchedContent.of(postService.getContentById(nextPost.getId()))); + nextPost.setContent( + Content.PatchedContent.of(postService.getContentById(nextPost.getId()))); return postService.convertToDetailVo(nextPost); }