Skip to content

Commit a460569

Browse files
authored
[chore] 불필요한 수정 되돌리기 #230 (#233)
* Revert "chore: initData용 이미지 추가" This reverts commit ef30eef. * . * chore: 수정 사항 없음 * fix: 삭제되지 않은 댓글만 조회하는 기능 추가 * chore: 불필요한 fix 롤백 * chore: 수정사항 없음
1 parent 613956d commit a460569

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.back.domain.post.comment.repository;
22

33
import com.back.domain.post.comment.entity.Comment;
4-
import com.back.domain.post.comment.enums.CommentStatus;
54
import org.springframework.data.jpa.repository.JpaRepository;
65
import org.springframework.stereotype.Repository;
76

@@ -13,9 +12,4 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {
1312
List<Comment> findTop10ByPostIdOrderByIdDesc(Long postId);
1413

1514
List<Comment> findTop10ByPostIdAndIdLessThanOrderByIdDesc(Long postId, Long lastId);
16-
17-
// DELETED가 아닌 댓글만 조회하는 메서드 추가
18-
List<Comment> findTop10ByPostIdAndStatusNotOrderByIdDesc(Long postId, CommentStatus status);
19-
20-
List<Comment> findTop10ByPostIdAndStatusNotAndIdLessThanOrderByIdDesc(Long postId, CommentStatus status, Long lastId);
2115
}

src/main/java/com/back/domain/post/comment/service/CommentService.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ public CommentResponseDto createComment(Long postId, CommentCreateRequestDto req
6868
@Transactional(readOnly = true)
6969
public List<CommentResponseDto> getComments(Long postId, Long lastId) {
7070
if (lastId == null) {
71-
return commentRepository.findTop10ByPostIdAndStatusNotOrderByIdDesc(postId, CommentStatus.DELETED)
72-
.stream()
73-
.map(CommentResponseDto::new)
74-
.toList();
71+
return commentRepository.findTop10ByPostIdOrderByIdDesc(postId)
72+
.stream()
73+
.map(CommentResponseDto::new)
74+
.toList();
7575
} else {
76-
return commentRepository.findTop10ByPostIdAndStatusNotAndIdLessThanOrderByIdDesc(postId, CommentStatus.DELETED, lastId)
77-
.stream()
78-
.map(CommentResponseDto::new)
79-
.toList();
76+
return commentRepository.findTop10ByPostIdAndIdLessThanOrderByIdDesc(postId, lastId)
77+
.stream()
78+
.map(CommentResponseDto::new)
79+
.toList();
8080
}
8181
}
8282

@@ -85,11 +85,6 @@ public List<CommentResponseDto> getComments(Long postId, Long lastId) {
8585
public CommentResponseDto getComment(Long postId, Long commentId) {
8686
Comment comment = findCommentWithValidation(postId, commentId);
8787

88-
// 삭제된 댓글 조회 방지
89-
if (comment.getStatus() == CommentStatus.DELETED) {
90-
throw new IllegalArgumentException("삭제된 댓글입니다.");
91-
}
92-
9388
return new CommentResponseDto(comment);
9489
}
9590

@@ -136,17 +131,12 @@ public void deleteComment(Long postId, Long commentId) {
136131
// 댓글과 게시글의 연관관계 검증
137132
private Comment findCommentWithValidation(Long postId, Long commentId) {
138133
Comment comment = commentRepository.findById(commentId)
139-
.orElseThrow(() -> new IllegalArgumentException("댓글이 존재하지 않습니다. id=" + commentId));
134+
.orElseThrow(() -> new IllegalArgumentException("댓글이 존재하지 않습니다. id=" + commentId));
140135

141136
if (!comment.getPost().getId().equals(postId)) {
142137
throw new IllegalStateException("댓글이 해당 게시글에 속하지 않습니다.");
143138
}
144139

145-
// 삭제된 댓글 접근 방지 (수정/삭제 시)
146-
if (comment.getStatus() == CommentStatus.DELETED) {
147-
throw new IllegalStateException("삭제된 댓글은 수정하거나 삭제할 수 없습니다.");
148-
}
149-
150140
return comment;
151141
}
152142
}

0 commit comments

Comments
 (0)