From 7d789a5e4fc3d2d7222bb5a41778faae98205519 Mon Sep 17 00:00:00 2001 From: Taehun88 Date: Fri, 21 Feb 2025 12:39:41 +0900 Subject: [PATCH] fix --- .../prdoit/dto/comment/CommentReplyRequestDto.java | 2 +- .../prdoit/dto/comment/CommentRequestDto.java | 2 +- .../prdoit/service/comment/CommentServiceImpl.java | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/example/prdoit/dto/comment/CommentReplyRequestDto.java b/src/main/java/com/example/prdoit/dto/comment/CommentReplyRequestDto.java index 53e4532..036fa8b 100644 --- a/src/main/java/com/example/prdoit/dto/comment/CommentReplyRequestDto.java +++ b/src/main/java/com/example/prdoit/dto/comment/CommentReplyRequestDto.java @@ -13,6 +13,6 @@ public class CommentReplyRequestDto { private int commentId; // 대댓글이 달릴 원본 댓글 ID private String commentReplyContent; // 대댓글 내용 - private String commentReplyNickname; // 대댓글 작성자 닉네임 + private String userId; private LocalDateTime commentReplyDate; // 대댓글 작성 날짜 } diff --git a/src/main/java/com/example/prdoit/dto/comment/CommentRequestDto.java b/src/main/java/com/example/prdoit/dto/comment/CommentRequestDto.java index f74a319..ccf8c85 100644 --- a/src/main/java/com/example/prdoit/dto/comment/CommentRequestDto.java +++ b/src/main/java/com/example/prdoit/dto/comment/CommentRequestDto.java @@ -13,6 +13,6 @@ public class CommentRequestDto { private String contentId; // 댓글 달릴 게시글 ID private String commentContent; // 댓글 내용 - private String commentNickname; // 댓글 작성자 닉네임 + private String userId; // 댓글 작성자 닉네임 private LocalDateTime commentDate; // 댓글 작성 날짜 } diff --git a/src/main/java/com/example/prdoit/service/comment/CommentServiceImpl.java b/src/main/java/com/example/prdoit/service/comment/CommentServiceImpl.java index 87f5b5e..a4fe004 100644 --- a/src/main/java/com/example/prdoit/service/comment/CommentServiceImpl.java +++ b/src/main/java/com/example/prdoit/service/comment/CommentServiceImpl.java @@ -2,10 +2,7 @@ import com.example.prdoit.dto.comment.*; import com.example.prdoit.exception.CustomException; -import com.example.prdoit.model.CommentCommentTable; -import com.example.prdoit.model.CommentTable; -import com.example.prdoit.model.ContentTable; -import com.example.prdoit.model.NotificationTable; +import com.example.prdoit.model.*; import com.example.prdoit.repository.*; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -61,9 +58,11 @@ public void postComment(CommentRequestDto commentRequestDto) { ContentTable contentTable = contentTableRepository.findById(commentRequestDto.getContentId()) .orElseThrow(() -> new CustomException("해당 게시글이 없습니다.")); + IdTable idTable = idTableRepository.findById(commentRequestDto.getUserId()).orElseThrow(()-> new CustomException("해당 아이디가 존재하지 않습니다.")); + commentTableRepository.save(CommentTable.builder() .commentContent(commentRequestDto.getCommentContent()) - .commentNickname(commentRequestDto.getCommentNickname()) + .commentNickname(idTable.getNickname()) .commentDate(commentRequestDto.getCommentDate()) .contentId(contentTable) .build()); @@ -87,9 +86,11 @@ public void postCommentReply(CommentReplyRequestDto commentReplyRequestDto) { CommentTable parentComment = commentTableRepository.findById(commentReplyRequestDto.getCommentId()) .orElseThrow(() -> new CustomException("해당 댓글이 없습니다.")); + IdTable idTable = idTableRepository.findById(commentReplyRequestDto.getUserId()).orElseThrow(()->new CustomException("해당아이디가 존재하지 않습니다.")); + commentCommentTableRepository.save(CommentCommentTable.builder() .commentCommentContent(commentReplyRequestDto.getCommentReplyContent()) - .userNickname(commentReplyRequestDto.getCommentReplyNickname()) + .userNickname(idTable.getNickname()) .commentCommentDate(commentReplyRequestDto.getCommentReplyDate()) .commentId(parentComment) .build());