4
4
import com .drinkeg .drinkeg .domain .model .BaseEntity ;
5
5
import com .drinkeg .drinkeg .domain .member .domain .Member ;
6
6
import com .drinkeg .drinkeg .domain .party .domain .Party ;
7
- import com .drinkeg .drinkeg .domain .recomment .domain .Recomment ;
8
7
import jakarta .persistence .*;
9
8
import lombok .*;
10
9
@@ -20,6 +19,13 @@ public class Comment extends BaseEntity {
20
19
@ GeneratedValue (strategy = GenerationType .IDENTITY )
21
20
private Long id ;
22
21
22
+ @ ManyToOne (fetch = FetchType .LAZY )
23
+ @ JoinColumn (name = "parent_id" )
24
+ private Comment parent ;
25
+
26
+ @ OneToMany (mappedBy = "parent" , cascade = CascadeType .ALL , orphanRemoval = true )
27
+ private List <Comment > children = new ArrayList <>();
28
+
23
29
@ ManyToOne (fetch = FetchType .LAZY )
24
30
@ JoinColumn (name = "party_id" )
25
31
private Party party ;
@@ -30,8 +36,6 @@ public class Comment extends BaseEntity {
30
36
31
37
private String content ;
32
38
33
- @ OneToMany (mappedBy = "comment" , cascade = CascadeType .ALL , orphanRemoval = true )
34
- private List <Recomment > recomments ;
35
39
36
40
private boolean isDeleted = false ;
37
41
@@ -40,25 +44,30 @@ public static Comment create(Member member, Party party, String content) {
40
44
.member (member )
41
45
.party (party )
42
46
.content (content )
47
+ .isDeleted (false )
43
48
.build ();
44
49
}
45
50
46
51
@ Builder
47
- public Comment (Party party , Member member , String content , List <Recomment > recomments ) {
52
+ public Comment (Comment parent , Party party , Member member , String content , boolean isDeleted ) {
53
+ this .parent = parent ;
48
54
this .party = party ;
49
55
this .member = member ;
50
56
this .content = content ;
51
- this .recomments = recomments != null ? recomments : new ArrayList <>();
52
57
this .isDeleted = false ;
53
58
}
54
59
55
- public void addRecomment (Recomment recomment ) {
56
- this .recomments .add (recomment );
57
- recomment .setParentComment (this ); // 자식의 참조도 설정
60
+
61
+ public void addChild (Comment child ) {
62
+ this .children .add (child );
63
+ child .parent = this ;
64
+ }
65
+
66
+ public void softDelete () {
67
+ this .isDeleted = true ;
58
68
}
59
69
60
- public void removeRecomment (Recomment recomment ) {
61
- this .recomments .remove (recomment );
62
- recomment .setParentComment (null ); // 자식의 부모 참조 제거
70
+ public void updateContent (String newContent ) {
71
+ this .content = newContent ;
63
72
}
64
73
}
0 commit comments