diff --git a/src/main/java/com/example/stepperbackend/repository/CommentRepository.java b/src/main/java/com/example/stepperbackend/repository/CommentRepository.java index 21c394b..e2b148d 100644 --- a/src/main/java/com/example/stepperbackend/repository/CommentRepository.java +++ b/src/main/java/com/example/stepperbackend/repository/CommentRepository.java @@ -23,4 +23,6 @@ public interface CommentRepository extends JpaRepository { @Query("SELECT e FROM Comment e WHERE e.post.id = :postId") List findByPostId(@Param("postId") Long postId); + + } diff --git a/src/main/java/com/example/stepperbackend/repository/PostRepository.java b/src/main/java/com/example/stepperbackend/repository/PostRepository.java index b4e9f89..205d5c9 100644 --- a/src/main/java/com/example/stepperbackend/repository/PostRepository.java +++ b/src/main/java/com/example/stepperbackend/repository/PostRepository.java @@ -9,6 +9,7 @@ import org.springframework.data.repository.query.Param; import java.util.List; +import java.util.Optional; public interface PostRepository extends JpaRepository { @@ -20,5 +21,5 @@ public interface PostRepository extends JpaRepository { @Query("SELECT e FROM Post e WHERE e.bodyPart = :bodypart") List findByCategoryId(@Param("bodypart") BodyPart bodyPart); - + Optional findAllByMemberId(Long memberId); } diff --git a/src/main/java/com/example/stepperbackend/service/CommentService/CommentServiceImpl.java b/src/main/java/com/example/stepperbackend/service/CommentService/CommentServiceImpl.java index d6e1b32..e518f50 100644 --- a/src/main/java/com/example/stepperbackend/service/CommentService/CommentServiceImpl.java +++ b/src/main/java/com/example/stepperbackend/service/CommentService/CommentServiceImpl.java @@ -43,13 +43,18 @@ public CommentDto.CommentResponseDto writeComment(CommentDto.CommentRequestDto r Post post = postRepository.findById(request.getPostId()) .orElseThrow(() -> new PostHandler(ErrorStatus.POST_NOT_FOUND)); + List commentList = commentRepository.findByPost_IdAndMember_Id(post.getId(), member.getId()); String memberName; + Long writerId = post.getMember().getId(); + - if (request.isAnonymous()) { + if(writerId.equals(member.getId())){ + memberName = member.getName() + "(작성자)"; + } else if (request.isAnonymous()) { memberName = getAnonymousName(commentList, post.getId()); - } else { + } else{ memberName = member.getName(); } @@ -75,8 +80,12 @@ public CommentDto.CommentResponseDto writeReply(CommentDto.ReplyRequestDto reque List commentList = commentRepository.findByPost_IdAndMember_Id(post.getId(), member.getId()); String memberName; + Long writerId = post.getMember().getId(); + - if (request.isAnonymous()) { + if(writerId.equals(member.getId())){ + memberName = member.getName() + "(작성자)"; + } else if (request.isAnonymous()) { memberName = getAnonymousName(commentList, post.getId()); } else { memberName = member.getName();