Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Post and sheet content is empty in the Content API #1686

Merged
merged 2 commits into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
JohnNiang marked this conversation as resolved.
Show resolved Hide resolved
post.setContent(Content.PatchedContent.of(postService.getContentById(postId)));
PostDetailVO postDetailVO = postService.convertToDetailVo(post);

if (formatDisabled) {
// Clear the format content
Expand All @@ -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
Expand All @@ -152,6 +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())));
return postService.convertToDetailVo(prevPost);
}

Expand All @@ -161,6 +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())));
return postService.convertToDetailVo(nextPost);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
JohnNiang marked this conversation as resolved.
Show resolved Hide resolved
sheet.setContent(Content.PatchedContent.of(sheetService.getContentById(sheetId)));
SheetDetailVO sheetDetailVO = sheetService.convertToDetailVo(sheet);

if (formatDisabled) {
// Clear the format content
Expand All @@ -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
Expand Down