|
|
@@ -10,7 +10,6 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -33,9 +32,9 @@ public class CommentServiceImpl implements CommentService {
|
|
|
comment.setUserType(userType);
|
|
|
comment.setItemId(commentDTO.getItemId());
|
|
|
comment.setContent(commentDTO.getContent());
|
|
|
- comment.setFollowComments(Collections.emptySet());
|
|
|
|
|
|
Integer fatherCommentId = commentDTO.getFatherCommentId();
|
|
|
+
|
|
|
if (fatherCommentId != null && fatherCommentId > 0) {
|
|
|
Comment fatherComment = commentDAO.findCommentById(fatherCommentId);
|
|
|
comment.setFatherComment(fatherComment);
|
|
|
@@ -46,14 +45,24 @@ public class CommentServiceImpl implements CommentService {
|
|
|
|
|
|
@Override
|
|
|
public List<CommentVO> getComments(Integer itemId, Pageable pageable) {
|
|
|
- Page<Comment> commentPage = commentDAO.findByItemId(itemId, pageable);
|
|
|
- return commentPage
|
|
|
- .getContent()
|
|
|
+ Page<Comment> commentPage = commentDAO.findByItemIdAndFatherCommentIsNull(itemId, pageable);
|
|
|
+ List<Comment> comments = commentPage.getContent();
|
|
|
+ return comments
|
|
|
.stream()
|
|
|
- .map(CommentVO::new)
|
|
|
+ .map(this::getCommentVO)
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ private CommentVO getCommentVO(Comment comment) {
|
|
|
+ List<Comment> childComments = commentDAO.findByFatherCommentOrderByPublishTimeAsc(comment);
|
|
|
+ return new CommentVO(
|
|
|
+ comment, childComments
|
|
|
+ .stream()
|
|
|
+ .map(this::getCommentVO)
|
|
|
+ .collect(Collectors.toList())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void deleteComment(Integer commentId) {
|
|
|
commentDAO.deleteById(commentId);
|