Skip to content

Commit

Permalink
Merge pull request #103 from STEPPER-UMC-6th/feat/102
Browse files Browse the repository at this point in the history
[Feat] 댓글,대댓글 작성시 게시물 작성자 구별 기능
  • Loading branch information
lehojun authored Aug 12, 2024
2 parents ad81af2 + ff666a2 commit f253beb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {

@Query("SELECT e FROM Comment e WHERE e.post.id = :postId")
List<Comment> findByPostId(@Param("postId") Long postId);


}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface PostRepository extends JpaRepository<Post, Long> {

Expand All @@ -20,5 +21,5 @@ public interface PostRepository extends JpaRepository<Post, Long> {
@Query("SELECT e FROM Post e WHERE e.bodyPart = :bodypart")
List<Post> findByCategoryId(@Param("bodypart") BodyPart bodyPart);


Optional<Post> findAllByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Comment> 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();
}

Expand All @@ -75,8 +80,12 @@ public CommentDto.CommentResponseDto writeReply(CommentDto.ReplyRequestDto reque
List<Comment> 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();
Expand Down

0 comments on commit f253beb

Please sign in to comment.