From b7fa57902e0d6d5175f20944f3f19de4142dcbe5 Mon Sep 17 00:00:00 2001 From: johnniang Date: Wed, 3 Apr 2019 10:34:04 +0800 Subject: [PATCH] Move comment list api from admin to portal --- .../controller/admin/api/PostController.java | 20 ----------- .../controller/portal/api/PostController.java | 33 ++++++++++++++++++- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/api/PostController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/api/PostController.java index ded606264..5aa9341bd 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/admin/api/PostController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/admin/api/PostController.java @@ -5,17 +5,12 @@ import cc.ryanc.halo.model.dto.post.PostSimpleOutputDTO; import cc.ryanc.halo.model.entity.Post; import cc.ryanc.halo.model.enums.PostStatus; import cc.ryanc.halo.model.params.PostParam; -import cc.ryanc.halo.model.vo.CommentWithParentVO; -import cc.ryanc.halo.model.vo.CommentVO; import cc.ryanc.halo.model.vo.PostDetailVO; import cc.ryanc.halo.service.*; import io.swagger.annotations.ApiOperation; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; import org.springframework.data.web.PageableDefault; -import org.springframework.data.web.SortDefault; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; @@ -104,19 +99,4 @@ public class PostController { postTagService.removeByPostId(postId); } - @GetMapping("{postId:\\d+}/comments/tree_view") - @ApiOperation("Lists comments with tree view") - public Page listCommentsTree(@PathVariable("postId") Integer postId, - @RequestParam(name = "page", required = false, defaultValue = "0") int page, - @SortDefault(sort = "createTime", direction = DESC) Sort sort) { - return commentService.pageVosBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); - } - - @GetMapping("{postId:\\d+}/comments/list_view") - @ApiOperation("Lists comment with list view") - public Page listComments(@PathVariable("postId") Integer postId, - @RequestParam(name = "page", required = false, defaultValue = "0") int page, - @SortDefault(sort = "createTime", direction = DESC) Sort sort) { - return commentService.pageWithParentVoBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); - } } diff --git a/src/main/java/cc/ryanc/halo/web/controller/portal/api/PostController.java b/src/main/java/cc/ryanc/halo/web/controller/portal/api/PostController.java index 48b4731cb..0523e74e3 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/portal/api/PostController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/portal/api/PostController.java @@ -3,11 +3,18 @@ package cc.ryanc.halo.web.controller.portal.api; import cc.ryanc.halo.model.dto.post.PostDetailOutputDTO; import cc.ryanc.halo.model.dto.post.PostSimpleOutputDTO; import cc.ryanc.halo.model.enums.PostStatus; +import cc.ryanc.halo.model.vo.CommentVO; +import cc.ryanc.halo.model.vo.CommentWithParentVO; +import cc.ryanc.halo.service.CommentService; +import cc.ryanc.halo.service.OptionService; import cc.ryanc.halo.service.PostService; import io.swagger.annotations.ApiOperation; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.web.PageableDefault; +import org.springframework.data.web.SortDefault; import org.springframework.web.bind.annotation.*; import static org.springframework.data.domain.Sort.Direction.DESC; @@ -24,8 +31,16 @@ public class PostController { private final PostService postService; - public PostController(PostService postService) { + private final CommentService commentService; + + private final OptionService optionService; + + public PostController(PostService postService, + CommentService commentService, + OptionService optionService) { this.postService = postService; + this.commentService = commentService; + this.optionService = optionService; } @GetMapping @@ -53,4 +68,20 @@ public class PostController { return postDetail; } + + @GetMapping("{postId:\\d+}/comments/tree_view") + @ApiOperation("Lists comments with tree view") + public Page listCommentsTree(@PathVariable("postId") Integer postId, + @RequestParam(name = "page", required = false, defaultValue = "0") int page, + @SortDefault(sort = "createTime", direction = DESC) Sort sort) { + return commentService.pageVosBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); + } + + @GetMapping("{postId:\\d+}/comments/list_view") + @ApiOperation("Lists comment with list view") + public Page listComments(@PathVariable("postId") Integer postId, + @RequestParam(name = "page", required = false, defaultValue = "0") int page, + @SortDefault(sort = "createTime", direction = DESC) Sort sort) { + return commentService.pageWithParentVoBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); + } }