diff --git a/src/main/java/econo/buddybridge/matching/entity/Matching.java b/src/main/java/econo/buddybridge/matching/entity/Matching.java index 8e20f28..ae8b178 100644 --- a/src/main/java/econo/buddybridge/matching/entity/Matching.java +++ b/src/main/java/econo/buddybridge/matching/entity/Matching.java @@ -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; @@ -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 chatMessages = new ArrayList<>(); + @Builder public Matching(Post post, Member taker, Member giver, MatchingStatus matchingStatus){ this.post = post; diff --git a/src/main/java/econo/buddybridge/post/entity/Post.java b/src/main/java/econo/buddybridge/post/entity/Post.java index 4dad67c..6896b64 100644 --- a/src/main/java/econo/buddybridge/post/entity/Post.java +++ b/src/main/java/econo/buddybridge/post/entity/Post.java @@ -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; @@ -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; @@ -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 matchings = new ArrayList<>(); + public void changeStatus(PostStatus status){ // 상태 변경 this.postStatus = status; }