diff --git a/src/main/java/EatPic/spring/domain/comment/converter/CommentConverter.java b/src/main/java/EatPic/spring/domain/comment/converter/CommentConverter.java index 5fa7aef..f7c5e06 100644 --- a/src/main/java/EatPic/spring/domain/comment/converter/CommentConverter.java +++ b/src/main/java/EatPic/spring/domain/comment/converter/CommentConverter.java @@ -10,9 +10,10 @@ import java.util.List; public class CommentConverter { - public static Comment WriteCommentDtoToComment(CommentRequestDTO.WriteCommentDto writeCommentDto, Card card, User user) { + public static Comment WriteCommentDtoToComment(CommentRequestDTO.WriteCommentDto writeCommentDto, Card card, User user, Comment parentComment) { return Comment.builder() .card(card) + .parentComment(parentComment) .user(user) .content(writeCommentDto.getContent()) .build(); @@ -24,6 +25,7 @@ public static CommentResponseDTO.WriteCommentResponseDTO CommentToWriteCommentRe .parentCommentId(comment.getParentComment()==null?null:comment.getParentComment().getId()) .cardId(comment.getCard().getId()) .content(comment.getContent()) + .userId(comment.getUser().getId()) .build(); } diff --git a/src/main/java/EatPic/spring/domain/comment/dto/CommentRequestDTO.java b/src/main/java/EatPic/spring/domain/comment/dto/CommentRequestDTO.java index 24bd5d9..3cb84ac 100644 --- a/src/main/java/EatPic/spring/domain/comment/dto/CommentRequestDTO.java +++ b/src/main/java/EatPic/spring/domain/comment/dto/CommentRequestDTO.java @@ -15,7 +15,6 @@ public class CommentRequestDTO { @AllArgsConstructor @NoArgsConstructor public static class WriteCommentDto{ - @NotNull private Long parentCommentId; @NotBlank(message = "내용은 필수입니다.") diff --git a/src/main/java/EatPic/spring/domain/comment/service/CommentServiceImpl.java b/src/main/java/EatPic/spring/domain/comment/service/CommentServiceImpl.java index 847ab8f..e1b2c24 100644 --- a/src/main/java/EatPic/spring/domain/comment/service/CommentServiceImpl.java +++ b/src/main/java/EatPic/spring/domain/comment/service/CommentServiceImpl.java @@ -43,8 +43,8 @@ public Comment writeComment(HttpServletRequest request, CommentRequestDTO.WriteC // 카드(피드) Card card = cardRepository.findById(cardId) .orElseThrow(() -> new ExceptionHandler(CARD_NOT_FOUND)); - - Comment comment = CommentConverter.WriteCommentDtoToComment(writeCommentDto,card,user); + Comment parentComment = writeCommentDto.getParentCommentId()!=null?commentRepository.findById(writeCommentDto.getParentCommentId()).orElseThrow(()->new ExceptionHandler(COMMENT_NOT_FOUND)) : null; + Comment comment = CommentConverter.WriteCommentDtoToComment(writeCommentDto,card,user, parentComment); commentRepository.save(comment); return comment;