Skip to content

Commit

Permalink
엔티티 내부에서 다른 엔티티 수정하는 부분 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
plere committed Oct 13, 2024
1 parent e44ad82 commit cadde84
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package co.kr.ticketing.adminconcert.concert.repository.entity;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.annotations.ColumnDefault;
Expand Down Expand Up @@ -67,9 +66,9 @@ public class ConcertEntity {
private PlaceEntity placeEntity;

@OneToMany(mappedBy = "concertEntity", fetch = FetchType.LAZY)
private final List<RoundEntity> roundEntities = new ArrayList<>();
private List<RoundEntity> roundEntities;
@OneToMany(mappedBy = "concertEntity", fetch = FetchType.LAZY)
private final List<ConcertSeatEntity> seatEntities = new ArrayList<>();
private List<ConcertSeatEntity> seatEntities;

@Builder
public ConcertEntity(Long id, LocalDateTime createdAt, LocalDateTime updatedAt, String name, String detailInfo,
Expand All @@ -87,32 +86,8 @@ public ConcertEntity(Long id, LocalDateTime createdAt, LocalDateTime updatedAt,
this.lastRunningEndTime = lastRunningEndTime;
this.openTime = openTime;
this.placeEntity = placeEntity;
setRoundEntities(roundEntities);
setSeatEntities(seatEntities);
}

public void setRoundEntities(List<RoundEntity> roundEntities) {
this.roundEntities.clear();
if (roundEntities != null) {
this.roundEntities.addAll(roundEntities);
roundEntities.forEach(roundEntity -> {
if (roundEntity.getConcertEntity() != this) {
roundEntity.setConcertEntity(this);
}
});
}
}

public void setSeatEntities(List<ConcertSeatEntity> seatEntities) {
this.seatEntities.clear();
if (seatEntities != null) {
this.seatEntities.addAll(seatEntities);
seatEntities.forEach(seatEntity -> {
if (seatEntity.getConcertEntity() != this) {
seatEntity.setConcertEntity(this);
}
});
}
this.roundEntities = roundEntities;
this.seatEntities = seatEntities;
}

public static ConcertEntity from(Concert concert, PlaceEntity placeEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,7 @@ public ConcertSeatEntity(Long id, LocalDateTime createdAt, LocalDateTime updated
this.rowNum = rowNum;
this.floor = floor;
this.state = state;
setConcertEntity(concertEntity);
}

public void setConcertEntity(ConcertEntity concertEntity) {
if (concertEntity != null) {
this.concertEntity = concertEntity;
if (!concertEntity.getSeatEntities().contains(this)) {
concertEntity.getSeatEntities().add(this);
}
}
this.concertEntity = concertEntity;
}

public static ConcertSeatEntity from(ConcertEntity concertEntity, ConcertSeat concertSeat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,7 @@ public RoundEntity(Long id, LocalDateTime createdAt, LocalDateTime updatedAt, Lo
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.startDateTime = startDateTime;
setConcertEntity(concertEntity);
}

void setConcertEntity(ConcertEntity concertEntity) {
if (concertEntity != null) {
this.concertEntity = concertEntity;
if (!concertEntity.getRoundEntities().contains(this)) {
concertEntity.getRoundEntities().add(this);
}
}
this.concertEntity = concertEntity;
}

public static RoundEntity from(ConcertEntity concertEntity, Round round) {
Expand Down

0 comments on commit cadde84

Please sign in to comment.