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

lzt
forely 2 weeks ago
parent 6eb3317273
commit 3b23ad399d

@ -1,5 +1,7 @@
package com.luojia_channel.modules.post.service; package com.luojia_channel.modules.post.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.dto.resp.CommentInfoDTO;
import com.luojia_channel.modules.post.entity.Comment; import com.luojia_channel.modules.post.entity.Comment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -15,7 +17,7 @@ public interface CommentService {
void deleteComment(Long id, Long userId); 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); List<CommentInfoDTO> getNestedCommentsByPostId(Long postId);
} }

@ -1,11 +1,18 @@
package com.luojia_channel.modules.post.service.impl; package com.luojia_channel.modules.post.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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.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.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.Comment;
import com.luojia_channel.modules.post.entity.Post;
import com.luojia_channel.modules.post.mapper.CommentMapper; import com.luojia_channel.modules.post.mapper.CommentMapper;
import com.luojia_channel.modules.post.service.CommentService; import com.luojia_channel.modules.post.service.CommentService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -48,22 +55,12 @@ public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> impl
} }
@Override @Override
public Page<CommentInfoDTO> getCommentsByPostId(Long postId, int pageNum, int pageSize) { public PageResponse<CommentInfoDTO> getCommentsByPostId(CommentPageQueryDTO commentPageQueryDTO) {
LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Comment> queryWrapper = Wrappers.lambdaQuery(Comment.class)
queryWrapper.eq(Comment::getPostId, postId) .eq(Comment::getPostId, commentPageQueryDTO.getPostId())
.isNull(Comment::getParentCommentId) .orderByDesc(Comment::getCreateTime);
.orderByAsc(Comment::getCreateTime); IPage<Comment> commentPage = commentMapper.selectPage(PageUtil.convert(commentPageQueryDTO), queryWrapper);
return PageUtil.convert(commentPage, CommentInfoDTO.class);
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;
} }
@Override @Override

Loading…
Cancel
Save