Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[고도화] 댓글 기능 고도화 - 1차 대댓글: 도메인 업데이트 #71

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.core.annotation.Order;

import javax.persistence.*;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;

@Getter
@ToString(callSuper = true)
Expand All @@ -29,21 +32,35 @@ public class ArticleComment extends AuditingFields {
@JoinColumn(name = "userId")
private UserAccount userAccount; // 유저 정보 (ID)

@Setter
@Column(updatable = false)
private Long parentCommentId; // 부모 댓글 ID

@ToString.Exclude
@OrderBy("createdAt ASC")
@OneToMany(mappedBy = "parentCommentId", cascade = CascadeType.ALL)
private Set<ArticleComment> childComments = new LinkedHashSet<>();

@Setter @Column(nullable = false, length = 500) private String content; // 본문


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
public boolean equals(Object o) {
if (this == o) return true;
Expand Down