Skip to content

Commit de3f558

Browse files
committed
#324 refactor: 댓글 entity refactor
1 parent 0179bec commit de3f558

File tree

1 file changed

+20
-11
lines changed
  • src/main/java/com/drinkeg/drinkeg/domain/comment/domain

1 file changed

+20
-11
lines changed

src/main/java/com/drinkeg/drinkeg/domain/comment/domain/Comment.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.drinkeg.drinkeg.domain.model.BaseEntity;
55
import com.drinkeg.drinkeg.domain.member.domain.Member;
66
import com.drinkeg.drinkeg.domain.party.domain.Party;
7-
import com.drinkeg.drinkeg.domain.recomment.domain.Recomment;
87
import jakarta.persistence.*;
98
import lombok.*;
109

@@ -20,6 +19,13 @@ public class Comment extends BaseEntity {
2019
@GeneratedValue(strategy = GenerationType.IDENTITY)
2120
private Long id;
2221

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+
2329
@ManyToOne(fetch = FetchType.LAZY)
2430
@JoinColumn(name = "party_id")
2531
private Party party;
@@ -30,8 +36,6 @@ public class Comment extends BaseEntity {
3036

3137
private String content;
3238

33-
@OneToMany(mappedBy = "comment", cascade = CascadeType.ALL, orphanRemoval = true)
34-
private List<Recomment> recomments;
3539

3640
private boolean isDeleted = false;
3741

@@ -40,25 +44,30 @@ public static Comment create(Member member, Party party, String content) {
4044
.member(member)
4145
.party(party)
4246
.content(content)
47+
.isDeleted(false)
4348
.build();
4449
}
4550

4651
@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;
4854
this.party = party;
4955
this.member = member;
5056
this.content = content;
51-
this.recomments = recomments != null ? recomments : new ArrayList<>();
5257
this.isDeleted = false;
5358
}
5459

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;
5868
}
5969

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;
6372
}
6473
}

0 commit comments

Comments
 (0)