Skip to content

Commit

Permalink
영속성 전이 (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschoi-96 authored Mar 30, 2024
1 parent 9d627ed commit 3ca8f23
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main/java/balancetalk/module/comment/domain/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public class Comment extends BaseTimeEntity {
@JoinColumn(name = "parent_id")
private Comment parent;

@OneToMany(mappedBy = "comment")
@OneToMany(mappedBy = "comment", cascade = CascadeType.ALL)
private List<CommentLike> likes = new ArrayList<>();

@OneToMany(mappedBy = "comment")
@OneToMany(mappedBy = "comment", cascade = CascadeType.ALL)
private List<Report> reports = new ArrayList<>();

public void updateContent(String content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ public void delete(final LoginRequest loginRequest, HttpServletRequest request)
if (!passwordEncoder.matches(loginRequest.getPassword(), member.getPassword())) {
throw new BalanceTalkException(ErrorCode.MISMATCHED_EMAIL_OR_PASSWORD);
}
List<Post> posts = member.getPosts();
if (posts != null) {
for (Post post : posts) {
post.removeMember();
}
}
memberRepository.deleteByEmail(member.getEmail());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class BalanceOption {
@JoinColumn(name = "post_id")
private Post post;

@OneToMany(mappedBy = "balanceOption")
@OneToMany(mappedBy = "balanceOption", cascade = CascadeType.ALL)
private List<Vote> votes = new ArrayList<>();

public int voteCount() {
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/balancetalk/module/post/domain/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ public class Post extends BaseTimeEntity {
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<BalanceOption> options = new ArrayList<>();

@OneToMany(mappedBy = "post")
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<PostLike> likes = new ArrayList<>();

@Formula("(select count(*) from post_like where post_like.post_id = post_id)")
private long likesCount;

@OneToMany(mappedBy = "post")
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<Comment> comments = new ArrayList<>();

@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<PostTag> postTags = new ArrayList<>();

@OneToMany(mappedBy = "post")
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<Bookmark> bookmarks = new ArrayList<>();

@OneToMany(mappedBy = "post")
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<Report> reports = new ArrayList<>();

public boolean isCasual() {
Expand All @@ -101,6 +101,10 @@ public void init() {
this.viewStatus = ViewStatus.NORMAL;
}

public void removeMember() {
this.member = null;
}

public boolean notContainsBalanceOption(BalanceOption option) {
return !options.contains(option);
}
Expand Down

0 comments on commit 3ca8f23

Please sign in to comment.