From dcc14f9190e4ecf7fa6f2459cc1056aea7e4f609 Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Thu, 1 Feb 2024 15:57:12 +0800 Subject: [PATCH] feat:cms comment list --- .../com/luoo/comment/controller/CommentController.java | 7 +++++++ .../src/main/java/com/luoo/comment/dao/CommentDao.java | 2 ++ .../main/java/com/luoo/comment/service/CommentService.java | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java index b190e4d..0d5ae7a 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java +++ b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java @@ -71,6 +71,13 @@ public class CommentController extends BaseController { } + @GetMapping("/{page}/{size}") + public Result search(@PathVariable int page,@PathVariable int size){ + Page pageData = commentService.search(page,size); + return Result.success(new PageResult(pageData.getTotalElements(),pageData.getContent())); + } + + @GetMapping("/{commentId}") public Result findById(@PathVariable String commentId){ return Result.success(commentService.findById(commentId)); diff --git a/luoo_comment/src/main/java/com/luoo/comment/dao/CommentDao.java b/luoo_comment/src/main/java/com/luoo/comment/dao/CommentDao.java index ad90c5e..0843c0d 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/dao/CommentDao.java +++ b/luoo_comment/src/main/java/com/luoo/comment/dao/CommentDao.java @@ -9,4 +9,6 @@ public interface CommentDao extends MongoRepository { public Page findByParentId(String parentId, Pageable pageable); public Page findByJournalId(String journalId, Pageable pageable); + + public Page findAllByOrderByPublishTimeDesc(Pageable pageable); } diff --git a/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java b/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java index c5ee503..77138c7 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java +++ b/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java @@ -127,4 +127,9 @@ public class CommentService { userMessageDto.setSendUserNickName(userLoginDto.getNickName()); rabbitTemplate.convertAndSend("userMessage",userMessageDto); } + + public Page search(int page, int size) { + Pageable pageable = PageRequest.of(page-1,size); + return commentDao.findAllByOrderByPublishTimeDesc(pageable); + } }