feat: 通过 slug 获取 sheet 或者文章 (#1044)

*  Feat: 通过fullpath获取sheet或者文章

* 🚀 Deploy: Fix CI

*  Feat: 通过slug获取文章详情

* 🔨 Refactor: 删除多余的import

* ️ Update: 重写自定义页面的接口,只使用slug获取页面

* Update: Remove unused import
pull/1665/head
宅家小能手 2020-08-28 00:08:19 +08:00 committed by GitHub
parent 6f88eeda32
commit 8c948fd670
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 0 deletions

View File

@ -88,6 +88,28 @@ public class PostController {
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")
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("postId") Integer postId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,

View File

@ -78,6 +78,28 @@ public class SheetController {
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")
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("sheetId") Integer sheetId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,

View File

@ -265,4 +265,5 @@ public interface PostService extends BasePostService<Post> {
*/
@NotNull
Sort getPostDefaultSort();
}

View File

@ -131,4 +131,5 @@ public interface SheetService extends BasePostService<Sheet> {
* @param sheetId sheetId must not be null
*/
void publishVisitEvent(@NonNull Integer sheetId);
}

View File

@ -358,4 +358,5 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
return fullPath.toString();
}
}