mirror of https://github.com/halo-dev/halo
feat: 通过 slug 获取 sheet 或者文章 (#1044)
* ✨ Feat: 通过fullpath获取sheet或者文章 * 🚀 Deploy: Fix CI * ✨ Feat: 通过slug获取文章详情 * 🔨 Refactor: 删除多余的import * ⚡️ Update: 重写自定义页面的接口,只使用slug获取页面 * Update: Remove unused importpull/1665/head
parent
6f88eeda32
commit
8c948fd670
|
@ -88,6 +88,28 @@ public class PostController {
|
||||||
return postDetailVO;
|
return postDetailVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/slug")
|
||||||
|
@ApiOperation("Gets a post")
|
||||||
|
public PostDetailVO getBy(@RequestParam("slug") String slug,
|
||||||
|
@RequestParam(value = "formatDisabled", required = false, defaultValue = "true") Boolean formatDisabled,
|
||||||
|
@RequestParam(value = "sourceDisabled", required = false, defaultValue = "false") Boolean sourceDisabled) {
|
||||||
|
PostDetailVO postDetailVO = postService.convertToDetailVo(postService.getBySlug(slug));
|
||||||
|
|
||||||
|
if (formatDisabled) {
|
||||||
|
// Clear the format content
|
||||||
|
postDetailVO.setFormatContent(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sourceDisabled) {
|
||||||
|
// Clear the original content
|
||||||
|
postDetailVO.setOriginalContent(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
postService.publishVisitEvent(postDetailVO.getId());
|
||||||
|
|
||||||
|
return postDetailVO;
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("{postId:\\d+}/comments/top_view")
|
@GetMapping("{postId:\\d+}/comments/top_view")
|
||||||
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("postId") Integer postId,
|
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("postId") Integer postId,
|
||||||
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
|
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
|
||||||
|
|
|
@ -78,6 +78,28 @@ public class SheetController {
|
||||||
return sheetDetailVO;
|
return sheetDetailVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/slug")
|
||||||
|
@ApiOperation("Gets a sheet by slug")
|
||||||
|
public SheetDetailVO getBy(@RequestParam("slug") String slug,
|
||||||
|
@RequestParam(value = "formatDisabled", required = false, defaultValue = "true") Boolean formatDisabled,
|
||||||
|
@RequestParam(value = "sourceDisabled", required = false, defaultValue = "false") Boolean sourceDisabled) {
|
||||||
|
SheetDetailVO sheetDetailVO = sheetService.convertToDetailVo(sheetService.getBySlug(slug));
|
||||||
|
|
||||||
|
if (formatDisabled) {
|
||||||
|
// Clear the format content
|
||||||
|
sheetDetailVO.setFormatContent(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sourceDisabled) {
|
||||||
|
// Clear the original content
|
||||||
|
sheetDetailVO.setOriginalContent(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
sheetService.publishVisitEvent(sheetDetailVO.getId());
|
||||||
|
|
||||||
|
return sheetDetailVO;
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("{sheetId:\\d+}/comments/top_view")
|
@GetMapping("{sheetId:\\d+}/comments/top_view")
|
||||||
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("sheetId") Integer sheetId,
|
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("sheetId") Integer sheetId,
|
||||||
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
|
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
|
||||||
|
|
|
@ -265,4 +265,5 @@ public interface PostService extends BasePostService<Post> {
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
Sort getPostDefaultSort();
|
Sort getPostDefaultSort();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,4 +131,5 @@ public interface SheetService extends BasePostService<Sheet> {
|
||||||
* @param sheetId sheetId must not be null
|
* @param sheetId sheetId must not be null
|
||||||
*/
|
*/
|
||||||
void publishVisitEvent(@NonNull Integer sheetId);
|
void publishVisitEvent(@NonNull Integer sheetId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -358,4 +358,5 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
|
||||||
|
|
||||||
return fullPath.toString();
|
return fullPath.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue