From a65b2c35ce4c438ef2dbc09d9ea1485aa88500d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=83=E1=85=AE=E1=84=8B?= =?UTF-8?q?=E1=85=AF=E1=86=AB?= Date: Wed, 20 Dec 2023 16:40:20 +0900 Subject: [PATCH] [SWM-412] Feat : video and summary relation mapping to oneToMany --- .../common/entity/jpa/SummaryEntity.java | 2 +- .../sroom/common/entity/jpa/VideoEntity.java | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/m9d/sroom/common/entity/jpa/SummaryEntity.java b/src/main/java/com/m9d/sroom/common/entity/jpa/SummaryEntity.java index 2949faf1..e54b1559 100644 --- a/src/main/java/com/m9d/sroom/common/entity/jpa/SummaryEntity.java +++ b/src/main/java/com/m9d/sroom/common/entity/jpa/SummaryEntity.java @@ -20,7 +20,7 @@ public class SummaryEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long summaryId; - @OneToOne + @ManyToOne @JoinColumn(name = "video_id") private VideoEntity video; diff --git a/src/main/java/com/m9d/sroom/common/entity/jpa/VideoEntity.java b/src/main/java/com/m9d/sroom/common/entity/jpa/VideoEntity.java index 116ce81b..5cb65b30 100644 --- a/src/main/java/com/m9d/sroom/common/entity/jpa/VideoEntity.java +++ b/src/main/java/com/m9d/sroom/common/entity/jpa/VideoEntity.java @@ -12,6 +12,7 @@ import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; +import java.util.Objects; @Entity @Table(name = "VIDEO") @@ -43,9 +44,10 @@ public class VideoEntity { @Embedded private Review review; - @OneToOne - @JoinColumn(name = "summary_id") - private SummaryEntity summary; + @OneToMany(mappedBy = "video") + private List summaries = new ArrayList(); + + private Long summaryId; private Integer materialStatus; @@ -75,7 +77,16 @@ public static VideoEntity create(Video video) { video.getMembership()); } + public SummaryEntity getSummary() { + return summaries.stream() + .filter(summary -> !summary.isModified()) + .filter(summary -> Objects.equals(summary.getSummaryId(), summaryId)) + .findFirst() + .orElse(null); + } + public void setSummary(SummaryEntity summary) { - this.summary = summary; + this.getSummaries().add(summary); + this.summaryId = summary.getSummaryId(); } }