diff --git a/src/main/java/run/halo/app/controller/content/api/CommentController.java b/src/main/java/run/halo/app/controller/content/api/CommentController.java deleted file mode 100644 index 1c7cb7ded..000000000 --- a/src/main/java/run/halo/app/controller/content/api/CommentController.java +++ /dev/null @@ -1,33 +0,0 @@ -package run.halo.app.controller.content.api; - -import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import run.halo.app.model.dto.BaseCommentDTO; -import run.halo.app.model.params.PostCommentParam; -import run.halo.app.service.PostCommentService; - -/** - * Portal comment controller. - * - * @author johnniang - * @date 4/3/19 - */ -@RestController("ApiContentCommentController") -@RequestMapping("/api/comments") -public class CommentController { - - private final PostCommentService postCommentService; - - public CommentController(PostCommentService postCommentService) { - this.postCommentService = postCommentService; - } - - @PostMapping - @ApiOperation("Comments a post") - public BaseCommentDTO comment(@RequestBody PostCommentParam postCommentParam) { - return postCommentService.convertTo(postCommentService.createBy(postCommentParam)); - } -} diff --git a/src/main/java/run/halo/app/controller/content/api/JournalController.java b/src/main/java/run/halo/app/controller/content/api/JournalController.java new file mode 100644 index 000000000..f64e02d09 --- /dev/null +++ b/src/main/java/run/halo/app/controller/content/api/JournalController.java @@ -0,0 +1,62 @@ +package run.halo.app.controller.content.api; + +import io.swagger.annotations.ApiOperation; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.data.web.SortDefault; +import org.springframework.web.bind.annotation.*; +import run.halo.app.model.dto.BaseCommentDTO; +import run.halo.app.model.params.JournalCommentParam; +import run.halo.app.model.vo.BaseCommentVO; +import run.halo.app.model.vo.BaseCommentWithParentVO; +import run.halo.app.service.JournalCommentService; +import run.halo.app.service.JournalService; +import run.halo.app.service.OptionService; + +import static org.springframework.data.domain.Sort.Direction.DESC; + +/** + * @author johnniang + * @date 19-4-26 + */ +@RestController("PortalJournalController") +@RequestMapping("/api/journals") +public class JournalController { + + private final JournalService journalService; + + private final JournalCommentService journalCommentService; + + private final OptionService optionService; + + public JournalController(JournalService journalService, + JournalCommentService journalCommentService, + OptionService optionService) { + this.journalService = journalService; + this.journalCommentService = journalCommentService; + this.optionService = optionService; + } + + @GetMapping("{sheetId:\\d+}/comments/tree_view") + @ApiOperation("Lists comments with tree view") + public Page listCommentsTree(@PathVariable("sheetId") Integer sheetId, + @RequestParam(name = "page", required = false, defaultValue = "0") int page, + @SortDefault(sort = "createTime", direction = DESC) Sort sort) { + return journalCommentService.pageVosBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); + } + + @GetMapping("{sheetId:\\d+}/comments/list_view") + @ApiOperation("Lists comment with list view") + public Page listComments(@PathVariable("sheetId") Integer sheetId, + @RequestParam(name = "page", required = false, defaultValue = "0") int page, + @SortDefault(sort = "createTime", direction = DESC) Sort sort) { + return journalCommentService.pageWithParentVoBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); + } + + @PostMapping("comments") + @ApiOperation("Comments a post") + public BaseCommentDTO comment(@RequestBody JournalCommentParam journalCommentParam) { + return journalCommentService.convertTo(journalCommentService.createBy(journalCommentParam)); + } +} 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 1f00a93b3..45428dac1 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 @@ -8,10 +8,12 @@ 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 run.halo.app.model.dto.BaseCommentDTO; import run.halo.app.model.dto.post.BasePostDetailDTO; import run.halo.app.model.dto.post.BasePostSimpleDTO; import run.halo.app.model.entity.Post; import run.halo.app.model.enums.PostStatus; +import run.halo.app.model.params.PostCommentParam; import run.halo.app.model.vo.BaseCommentVO; import run.halo.app.model.vo.BaseCommentWithParentVO; import run.halo.app.service.OptionService; @@ -87,6 +89,12 @@ public class PostController { return postCommentService.pageWithParentVoBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); } + @PostMapping("comments") + @ApiOperation("Comments a post") + public BaseCommentDTO comment(@RequestBody PostCommentParam postCommentParam) { + return postCommentService.convertTo(postCommentService.createBy(postCommentParam)); + } + @PostMapping("{postId:\\d+}/likes") @ApiOperation("Likes a post") public void like(@PathVariable("postId") Integer postId) {