Skip to content

Commit 48013d5

Browse files
committed
2 parents 085112c + a460569 commit 48013d5

File tree

6 files changed

+33
-37
lines changed

6 files changed

+33
-37
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
}

src/main/java/com/back/domain/user/entity/User.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.ArrayList;
1515
import java.util.Collection;
1616
import java.util.List;
17+
import java.util.Objects;
1718

1819
@Entity
1920
@Table(name = "users") // 예약어 충돌 방지를 위해 "users" 권장
@@ -70,6 +71,17 @@ public class User {
7071
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
7172
private List<PostLike> postLikes = new ArrayList<>();
7273

74+
@Override
75+
public boolean equals(Object o) {
76+
if (o == null || getClass() != o.getClass()) return false;
77+
User user = (User) o;
78+
return Objects.equals(id, user.id);
79+
}
80+
81+
@Override
82+
public int hashCode() {
83+
return Objects.hashCode(id);
84+
}
7385

7486
public boolean isAdmin() {
7587
return "ADMIN".equalsIgnoreCase(role);

src/main/java/com/back/global/security/SecurityUser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public SecurityUser(
3838
authorities
3939
);
4040

41-
4241
this.id = id;
4342
this.nickname = nickname;
4443
this.email = email;

src/main/resources/application-dev.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,6 @@ spring:
2929
encoding: UTF-8
3030
data-locations: classpath:data-h2.sql
3131

32-
cloud:
33-
aws:
34-
region:
35-
static: ap-northeast-2
36-
stack:
37-
auto: false
38-
credentials:
39-
access-key: ${AWS_ACCESS_KEY_ID} # 로컬용 더미값
40-
secret-key: ${AWS_SECRET_ACCESS_KEY}
41-
s3:
42-
bucket: team2-app-s3-bucket
4332

4433
# Swagger 설정
4534
springdoc:

src/main/resources/application.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ spring:
4747
user-info-uri: https://openapi.naver.com/v1/nid/me
4848
user-name-attribute: response
4949

50+
cloud:
51+
aws:
52+
region:
53+
static: ap-northeast-2
54+
stack:
55+
auto: false
56+
credentials:
57+
access-key: ${AWS_ACCESS_KEY_ID} # 로컬용 더미값
58+
secret-key: ${AWS_SECRET_ACCESS_KEY}
59+
s3:
60+
bucket: team2-app-s3-bucket
61+
5062
ai:
5163
openai:
5264
api-key: ${GEMINI_API_KEY}

0 commit comments

Comments
 (0)