Skip to content

Commit 4bee0c3

Browse files
authored
Merge pull request #471 from Team-0ops/develop
Develop
2 parents 34cad2a + 1a41f97 commit 4bee0c3

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎src/main/java/Oops/backend/domain/comment/entity/Comment.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import Oops.backend.domain.common.BaseEntity;
44
import Oops.backend.domain.post.entity.Post;
55
import Oops.backend.domain.user.entity.User;
6+
import Oops.backend.domain.commentReport.entity.CommentReport;
67
import jakarta.persistence.*;
78
import lombok.*;
89
import org.yaml.snakeyaml.comments.CommentType;
@@ -42,6 +43,12 @@ public class Comment extends BaseEntity {
4243
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
4344
private List<Comment> replyComments;
4445

46+
@OneToMany(mappedBy = "comment", cascade = CascadeType.ALL, orphanRemoval = true)
47+
private List<CommentLike> commentLikes;
48+
49+
@OneToMany(mappedBy = "comment", cascade = CascadeType.ALL, orphanRemoval = true)
50+
private List<CommentReport> commentReports;
51+
4552
@Builder
4653
private Comment(Post post, User user, String content){
4754

@@ -50,6 +57,8 @@ private Comment(Post post, User user, String content){
5057
this.user = user;
5158
this.content = content;
5259
this.replyComments = new ArrayList<>();
60+
this.commentLikes = new ArrayList<>();
61+
this.commentReports = new ArrayList<>();
5362

5463
}
5564

‎src/main/java/Oops/backend/domain/commentReport/entity/CommentReport.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class CommentReport extends BaseEntity{
1515
@JoinColumn(name = "reporter")
1616
private User reportUser;
1717

18-
@OneToOne(fetch = FetchType.LAZY)
18+
@ManyToOne(fetch = FetchType.LAZY)
1919
@JoinColumn(name = "target")
2020
private Comment comment;
2121

‎src/main/java/Oops/backend/domain/post/service/PostCommandServiceImpl.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,16 @@ public void deletePost(Long postId, User user) {
9595
postsOfPostGroup.remove(post);
9696
post.setPostGroup(null);
9797

98+
if (postsOfPostGroup.isEmpty()){
99+
postGroupCommandService.deletePostGroup(postGroup);
100+
}
101+
98102
// Lesson과의 연관 관계 제거
99103
List<Lesson> lessons = lessonQueryService.findLessonsByPost(post);
100104
lessons.forEach((lesson) -> lesson.setPost(null));
101105

102-
if (postsOfPostGroup.isEmpty()){
103-
postGroupCommandService.deletePostGroup(postGroup);
104-
}
106+
// Post 엔티티의 cascade 설정으로 Comment가 자동 삭제되고,
107+
// Comment 엔티티의 cascade 설정으로 CommentLike와 CommentReport도 자동 삭제됨
105108

106109
postRepository.delete(post);
107110

0 commit comments

Comments
 (0)