Skip to content

Commit

Permalink
[FEAT] 게시글 cascade 옵션 적용 (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
Profile-exe authored Jul 26, 2024
1 parent 760f7b5 commit db57bbe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/econo/buddybridge/matching/entity/Matching.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package econo.buddybridge.matching.entity;

import econo.buddybridge.chat.chatmessage.entity.ChatMessage;
import econo.buddybridge.common.persistence.BaseEntity;
import econo.buddybridge.member.entity.Member;
import econo.buddybridge.post.entity.Post;
import econo.buddybridge.post.entity.PostStatus;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -37,6 +40,9 @@ public class Matching extends BaseEntity {
@Enumerated(EnumType.STRING)
private MatchingStatus matchingStatus;

@OneToMany(mappedBy = "matching", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ChatMessage> chatMessages = new ArrayList<>();

@Builder
public Matching(Post post, Member taker, Member giver, MatchingStatus matchingStatus){
this.post = post;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/econo/buddybridge/post/entity/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@


import econo.buddybridge.common.persistence.BaseEntity;
import econo.buddybridge.matching.entity.Matching;
import econo.buddybridge.member.entity.DisabilityType;
import econo.buddybridge.member.entity.Member;
import econo.buddybridge.post.dto.PostReqDto;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
Expand All @@ -17,7 +19,10 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -67,6 +72,9 @@ public class Post extends BaseEntity {
@Enumerated(EnumType.STRING)
private DisabilityType disabilityType;

@OneToMany(mappedBy = "post", orphanRemoval = true, cascade = CascadeType.ALL)
private final List<Matching> matchings = new ArrayList<>();

public void changeStatus(PostStatus status){ // 상태 변경
this.postStatus = status;
}
Expand Down

0 comments on commit db57bbe

Please sign in to comment.