重构部分表与接口,新增帖子,评论的相关接口

lzt
forely 2 weeks ago
parent 6eb3317273
commit 3b23ad399d

@ -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<CommentInfoDTO> getCommentsByPostId(Long postId, int pageNum, int pageSize);
PageResponse<CommentInfoDTO> getCommentsByPostId(CommentPageQueryDTO commentPageQueryDTO);
List<CommentInfoDTO> getNestedCommentsByPostId(Long postId);
}

@ -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<CommentMapper, Comment> impl
}
@Override
public Page<CommentInfoDTO> getCommentsByPostId(Long postId, int pageNum, int pageSize) {
LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Comment::getPostId, postId)
.isNull(Comment::getParentCommentId)
.orderByAsc(Comment::getCreateTime);
Page<Comment> page = new Page<>(pageNum, pageSize);
commentMapper.selectPage(page, queryWrapper);
Page<CommentInfoDTO> commentInfoDTOS = new Page<>();
BeanUtils.copyProperties(page, commentInfoDTOS, "records");
List<CommentInfoDTO> records = convertToDTO(page.getRecords());
commentInfoDTOS.setRecords(records);
return commentInfoDTOS;
public PageResponse<CommentInfoDTO> getCommentsByPostId(CommentPageQueryDTO commentPageQueryDTO) {
LambdaQueryWrapper<Comment> queryWrapper = Wrappers.lambdaQuery(Comment.class)
.eq(Comment::getPostId, commentPageQueryDTO.getPostId())
.orderByDesc(Comment::getCreateTime);
IPage<Comment> commentPage = commentMapper.selectPage(PageUtil.convert(commentPageQueryDTO), queryWrapper);
return PageUtil.convert(commentPage, CommentInfoDTO.class);
}
@Override

Loading…
Cancel
Save