Skip to content

Commit

Permalink
[SWM-412] Feat : video and summary relation mapping to oneToMany
Browse files Browse the repository at this point in the history
  • Loading branch information
D-w-nJ committed Dec 20, 2023
1 parent 5dbce38 commit a65b2c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SummaryEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long summaryId;

@OneToOne
@ManyToOne
@JoinColumn(name = "video_id")
private VideoEntity video;

Expand Down
19 changes: 15 additions & 4 deletions src/main/java/com/m9d/sroom/common/entity/jpa/VideoEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Entity
@Table(name = "VIDEO")
Expand Down Expand Up @@ -43,9 +44,10 @@ public class VideoEntity {
@Embedded
private Review review;

@OneToOne
@JoinColumn(name = "summary_id")
private SummaryEntity summary;
@OneToMany(mappedBy = "video")
private List<SummaryEntity> summaries = new ArrayList<SummaryEntity>();

private Long summaryId;

private Integer materialStatus;

Expand Down Expand Up @@ -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();
}
}

0 comments on commit a65b2c3

Please sign in to comment.