From 5064837cf81d57da87713f07265ba1380531c426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=B6=E9=86=89?= <73400@163.com> Date: Sun, 27 Feb 2022 15:47:54 +0800 Subject: [PATCH] Fix the problem post and sheet contents are empty in the content API (#1686) * fix: Post and sheet content is empty in the Content API --- .../app/controller/content/api/PostController.java | 13 +++++++++++-- .../app/controller/content/api/SheetController.java | 9 +++++++-- 2 files changed, 18 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 2ca313eec..bafed62c0 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.cache.lock.CacheParam; 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 class PostController { 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 class PostController { 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,8 @@ public class PostController { 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 +168,8 @@ public class PostController { 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 c8b959d71..b5f01aef7 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.bind.annotation.RestController; 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 class SheetController { 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 class SheetController { 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