diff --git a/src/main/java/run/halo/app/controller/admin/api/JournalCommentController.java b/src/main/java/run/halo/app/controller/admin/api/JournalCommentController.java index 195688f4b..7025d80ba 100644 --- a/src/main/java/run/halo/app/controller/admin/api/JournalCommentController.java +++ b/src/main/java/run/halo/app/controller/admin/api/JournalCommentController.java @@ -2,16 +2,22 @@ package run.halo.app.controller.admin.api; 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 run.halo.app.model.dto.BaseCommentDTO; import run.halo.app.model.entity.JournalComment; import run.halo.app.model.enums.CommentStatus; import run.halo.app.model.params.CommentQuery; 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.model.vo.JournalCommentWithJournalVO; import run.halo.app.service.JournalCommentService; +import run.halo.app.service.OptionService; import java.util.List; @@ -29,8 +35,12 @@ public class JournalCommentController { private final JournalCommentService journalCommentService; - public JournalCommentController(JournalCommentService journalCommentService) { + private final OptionService optionService; + + public JournalCommentController(JournalCommentService journalCommentService, + OptionService optionService) { this.journalCommentService = journalCommentService; + this.optionService = optionService; } @GetMapping @@ -49,6 +59,22 @@ public class JournalCommentController { return journalCommentService.convertToWithJournalVo(latestComments); } + @GetMapping("{journalId:\\d+}/tree_view") + @ApiOperation("Lists comments with tree view") + public Page listCommentTree(@PathVariable("journalId") Integer journalId, + @RequestParam(name = "page", required = false, defaultValue = "0") int page, + @SortDefault(sort = "createTime", direction = DESC) Sort sort) { + return journalCommentService.pageVosBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); + } + + @GetMapping("{journalId:\\d+}/list_view") + @ApiOperation("Lists comment with list view") + public Page listComments(@PathVariable("journalId") Integer journalId, + @RequestParam(name = "page", required = false, defaultValue = "0") int page, + @SortDefault(sort = "createTime", direction = DESC) Sort sort) { + return journalCommentService.pageWithParentVoBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); + } + @PostMapping @ApiOperation("Creates a journal comment") public BaseCommentDTO createCommentBy(@RequestBody JournalCommentParam journalCommentParam) { diff --git a/src/main/java/run/halo/app/controller/admin/api/JournalController.java b/src/main/java/run/halo/app/controller/admin/api/JournalController.java index d4fe65f50..9f8cfaf32 100644 --- a/src/main/java/run/halo/app/controller/admin/api/JournalController.java +++ b/src/main/java/run/halo/app/controller/admin/api/JournalController.java @@ -2,22 +2,15 @@ package run.halo.app.controller.admin.api; 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 run.halo.app.model.dto.JournalDTO; import run.halo.app.model.dto.JournalWithCmtCountDTO; import run.halo.app.model.entity.Journal; import run.halo.app.model.params.JournalParam; import run.halo.app.model.params.JournalQuery; -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 javax.validation.Valid; import java.util.List; @@ -29,7 +22,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC; * * @author johnniang * @author ryanwang - * @date 19-4-25 + * @date 2019-04-25 */ @RestController @RequestMapping("/api/admin/journals") @@ -37,16 +30,8 @@ public class JournalController { private final JournalService journalService; - private final JournalCommentService journalCommentService; - - private final OptionService optionService; - - public JournalController(JournalService journalService, - JournalCommentService journalCommentService, - OptionService optionService) { + public JournalController(JournalService journalService) { this.journalService = journalService; - this.journalCommentService = journalCommentService; - this.optionService = optionService; } @GetMapping @@ -86,20 +71,4 @@ public class JournalController { Journal deletedJournal = journalService.removeById(journalId); return journalService.convertTo(deletedJournal); } - - @GetMapping("{journalId:\\d+}/comments/tree_view") - @ApiOperation("Lists comments with tree view") - public Page listCommentTree(@PathVariable("journalId") Integer journalId, - @RequestParam(name = "page", required = false, defaultValue = "0") int page, - @SortDefault(sort = "createTime", direction = DESC) Sort sort) { - return journalCommentService.pageVosBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); - } - - @GetMapping("{journalId:\\d+}/comments/list_view") - @ApiOperation("Lists comment with list view") - public Page listComments(@PathVariable("journalId") Integer journalId, - @RequestParam(name = "page", required = false, defaultValue = "0") int page, - @SortDefault(sort = "createTime", direction = DESC) Sort sort) { - return journalCommentService.pageWithParentVoBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); - } } diff --git a/src/main/java/run/halo/app/controller/admin/api/PostCommentController.java b/src/main/java/run/halo/app/controller/admin/api/PostCommentController.java index 6c7a16e3d..3a151fceb 100644 --- a/src/main/java/run/halo/app/controller/admin/api/PostCommentController.java +++ b/src/main/java/run/halo/app/controller/admin/api/PostCommentController.java @@ -2,15 +2,21 @@ package run.halo.app.controller.admin.api; 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 run.halo.app.model.dto.BaseCommentDTO; import run.halo.app.model.entity.PostComment; import run.halo.app.model.enums.CommentStatus; import run.halo.app.model.params.CommentQuery; 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.model.vo.PostCommentWithPostVO; +import run.halo.app.service.OptionService; import run.halo.app.service.PostCommentService; import javax.validation.Valid; @@ -23,7 +29,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC; * * @author johnniang * @author ryanwang - * @date 3/19/19 + * @date 2019-03-29 */ @RestController @RequestMapping("/api/admin/posts/comments") @@ -31,8 +37,12 @@ public class PostCommentController { private final PostCommentService postCommentService; - public PostCommentController(PostCommentService postCommentService) { + private final OptionService optionService; + + public PostCommentController(PostCommentService postCommentService, + OptionService optionService) { this.postCommentService = postCommentService; + this.optionService = optionService; } @GetMapping @@ -54,6 +64,22 @@ public class PostCommentController { return postCommentService.convertToWithPostVo(content); } + @GetMapping("{postId:\\d+}/tree_view") + @ApiOperation("Lists comments with tree view") + public Page listCommentTree(@PathVariable("postId") Integer postId, + @RequestParam(name = "page", required = false, defaultValue = "0") int page, + @SortDefault(sort = "createTime", direction = DESC) Sort sort) { + return postCommentService.pageVosBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); + } + + @GetMapping("{postId:\\d+}/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 postCommentService.pageWithParentVoBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); + } + @PostMapping @ApiOperation("Creates a comment (new or reply)") public BaseCommentDTO createBy(@RequestBody PostCommentParam postCommentParam) { diff --git a/src/main/java/run/halo/app/controller/admin/api/SheetCommentController.java b/src/main/java/run/halo/app/controller/admin/api/SheetCommentController.java index ce8445249..1e1896dc8 100644 --- a/src/main/java/run/halo/app/controller/admin/api/SheetCommentController.java +++ b/src/main/java/run/halo/app/controller/admin/api/SheetCommentController.java @@ -2,15 +2,21 @@ package run.halo.app.controller.admin.api; 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 run.halo.app.model.dto.BaseCommentDTO; import run.halo.app.model.entity.SheetComment; import run.halo.app.model.enums.CommentStatus; import run.halo.app.model.params.CommentQuery; import run.halo.app.model.params.SheetCommentParam; +import run.halo.app.model.vo.BaseCommentVO; +import run.halo.app.model.vo.BaseCommentWithParentVO; import run.halo.app.model.vo.SheetCommentWithSheetVO; +import run.halo.app.service.OptionService; import run.halo.app.service.SheetCommentService; import javax.validation.Valid; @@ -23,7 +29,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC; * * @author johnniang * @author ryanwang - * @date 19-4-25 + * @date 2019-04-25 */ @RestController @RequestMapping("/api/admin/sheets/comments") @@ -31,8 +37,12 @@ public class SheetCommentController { private final SheetCommentService sheetCommentService; - public SheetCommentController(SheetCommentService sheetCommentService) { + private final OptionService optionService; + + public SheetCommentController(SheetCommentService sheetCommentService, + OptionService optionService) { this.sheetCommentService = sheetCommentService; + this.optionService = optionService; } @GetMapping @@ -49,6 +59,22 @@ public class SheetCommentController { return sheetCommentService.convertToWithSheetVo(sheetCommentPage.getContent()); } + @GetMapping("{sheetId:\\d+}/tree_view") + @ApiOperation("Lists comments with tree view") + public Page listCommentTree(@PathVariable("sheetId") Integer sheetId, + @RequestParam(name = "page", required = false, defaultValue = "0") int page, + @SortDefault(sort = "createTime", direction = DESC) Sort sort) { + return sheetCommentService.pageVosBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); + } + + @GetMapping("{sheetId:\\d+}/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 sheetCommentService.pageWithParentVoBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort)); + } + @PostMapping @ApiOperation("Creates a comment (new or reply)") public BaseCommentDTO createBy(@RequestBody SheetCommentParam commentParam) {