#16 board: child comment - update domain

This commit is contained in:
haerong22
2023-01-22 01:15:24 +09:00
parent ad95e5d318
commit 54b720e6ea

View File

@@ -5,7 +5,9 @@ import lombok.Setter;
import lombok.ToString;
import javax.persistence.*;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
@Getter
@ToString(callSuper = true)
@@ -26,6 +28,15 @@ public class ArticleComment extends AuditingFields {
@JoinColumn(name = "userId")
private UserAccount userAccount;
@Setter
@Column(updatable = false)
private Long parentCommentId;
@ToString.Exclude
@OrderBy("createdAt ASC")
@OneToMany(mappedBy = "parentCommentId", cascade = CascadeType.ALL)
private Set<ArticleComment> childComments = new LinkedHashSet<>();
@Setter
@ManyToOne(optional = false)
private Article article; // 게시글 (ID)
@@ -36,14 +47,20 @@ public class ArticleComment extends AuditingFields {
protected ArticleComment() {}
private ArticleComment(Article article, UserAccount userAccount, String content) {
private ArticleComment(Article article, UserAccount userAccount, Long parentCommentId, String content) {
this.article = article;
this.userAccount = userAccount;
this.parentCommentId = parentCommentId;
this.content = content;
}
public static ArticleComment of(Article article, UserAccount userAccount, String content) {
return new ArticleComment(article, userAccount, content);
return new ArticleComment(article, userAccount, null, content);
}
public void addChildComment(ArticleComment child) {
child.setParentCommentId(this.getId());
this.getChildComments().add(child);
}
@Override