diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/CommentService.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/CommentService.java index 71fd175..9523485 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/CommentService.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/CommentService.java @@ -1,5 +1,7 @@ package com.luojia_channel.modules.post.service; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.luojia_channel.common.domain.page.PageResponse; +import com.luojia_channel.modules.post.dto.req.CommentPageQueryDTO; import com.luojia_channel.modules.post.dto.resp.CommentInfoDTO; import com.luojia_channel.modules.post.entity.Comment; import org.springframework.stereotype.Service; @@ -15,7 +17,7 @@ public interface CommentService { void deleteComment(Long id, Long userId); - Page getCommentsByPostId(Long postId, int pageNum, int pageSize); + PageResponse getCommentsByPostId(CommentPageQueryDTO commentPageQueryDTO); List getNestedCommentsByPostId(Long postId); } diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/CommentServiceImpl.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/CommentServiceImpl.java index 0bc9e08..f78d52a 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/CommentServiceImpl.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/CommentServiceImpl.java @@ -1,11 +1,18 @@ package com.luojia_channel.modules.post.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.luojia_channel.common.domain.page.PageResponse; import com.luojia_channel.common.exception.PostException; +import com.luojia_channel.common.utils.PageUtil; +import com.luojia_channel.modules.post.dto.req.CommentPageQueryDTO; import com.luojia_channel.modules.post.dto.resp.CommentInfoDTO; +import com.luojia_channel.modules.post.dto.resp.PostBasicInfoDTO; import com.luojia_channel.modules.post.entity.Comment; +import com.luojia_channel.modules.post.entity.Post; import com.luojia_channel.modules.post.mapper.CommentMapper; import com.luojia_channel.modules.post.service.CommentService; import lombok.RequiredArgsConstructor; @@ -48,22 +55,12 @@ public class CommentServiceImpl extends ServiceImpl impl } @Override - public Page getCommentsByPostId(Long postId, int pageNum, int pageSize) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(Comment::getPostId, postId) - .isNull(Comment::getParentCommentId) - .orderByAsc(Comment::getCreateTime); - - Page page = new Page<>(pageNum, pageSize); - commentMapper.selectPage(page, queryWrapper); - - Page commentInfoDTOS = new Page<>(); - BeanUtils.copyProperties(page, commentInfoDTOS, "records"); - - List records = convertToDTO(page.getRecords()); - commentInfoDTOS.setRecords(records); - - return commentInfoDTOS; + public PageResponse getCommentsByPostId(CommentPageQueryDTO commentPageQueryDTO) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(Comment.class) + .eq(Comment::getPostId, commentPageQueryDTO.getPostId()) + .orderByDesc(Comment::getCreateTime); + IPage commentPage = commentMapper.selectPage(PageUtil.convert(commentPageQueryDTO), queryWrapper); + return PageUtil.convert(commentPage, CommentInfoDTO.class); } @Override