Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Schedule 관련 도메인 재설계 #88

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ app/.idea/
# Ignore Gradle build output directory
build
app/src/main/resources/application-secret.yml

# Ignore QFiles
app/src/main/generated/
app/out/

# Ignore MySQL bin Log
data/
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.picketing.www.business.domain;

import com.picketing.www.business.domain.schedule.Schedule;
import com.picketing.www.business.domain.show.seat.SeatGrade;

import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;

@Entity
@Table(name = "THEATER_SEAT_GRADE")
public class TheaterSeatGrade {

@Id
@GeneratedValue
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "schedule_id")
private Schedule theaterSchedule;

@Enumerated(EnumType.STRING)
private SeatGrade seatGrade;
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
package com.picketing.www.business.domain.schedule;

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

import com.picketing.www.persistence.table.BaseEntity;

import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;

@Entity
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder(access = AccessLevel.PROTECTED)
@Table(name = "DATE_SCHEDULE")
@Getter(AccessLevel.PROTECTED)
public class DateSchedule extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private LocalDate showDate; // 공연 일자

@Builder
public class DateSchedule {
@Getter
final Long id;
final Long showId;
final String name;
final LocalDate startDate;
final LocalDate endDate;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "schedule_id")
private Schedule schedule;

@Setter
List<TimeSchedule> timeSchedules;
@OneToMany(mappedBy = "dateSchedule")
private List<TimeSchedule> timeSchedules = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@

import org.springframework.stereotype.Component;

import com.picketing.www.persistence.table.schedule.DateSchedulePersist;

@Component
public class DateScheduleFactory {
public DateSchedule create(DateSchedulePersist dateSchedulePersist) {
return DateSchedule.builder()
.id(dateSchedulePersist.id())
.name(dateSchedulePersist.name())
.showId(dateSchedulePersist.showId())
.startDate(dateSchedulePersist.startDate())
.endDate(dateSchedulePersist.endDate())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,47 @@
package com.picketing.www.business.domain.schedule;

import java.util.ArrayList;
import java.util.List;

import com.picketing.www.business.domain.TheaterSeatGrade;
import com.picketing.www.business.domain.show.Show;
import com.picketing.www.persistence.table.BaseEntity;

import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Builder
@Entity
@Table(name = "SCHEDULE")
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter(AccessLevel.PROTECTED)
public class Schedule extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "show_id")
private Show show;

public class Schedule {
List<DateSchedule> dateSchedules;
// 공연장 정보
@OneToMany(mappedBy = "theaterSchedule")
private List<TheaterSeatGrade> theaterSeatGrades = new ArrayList<>(); // 공연장 정보

@Builder
public Schedule(List<DateSchedule> dateSchedules) {
this.dateSchedules = dateSchedules;
}
@OneToMany(mappedBy = "showSchedule")
private List<DateSchedule> dateSchedules = new ArrayList<>(); // 날짜 스케줄
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import org.springframework.stereotype.Component;

import com.picketing.www.persistence.table.schedule.DateSchedulePersist;
import com.picketing.www.persistence.table.schedule.DateScheduleView;
import com.picketing.www.presentation.dto.response.schedule.ScheduleResponseDto;
import com.picketing.www.presentation.dto.response.schedule.ScheduleResponseDto.DateScheduleResponseDto;
Expand All @@ -16,51 +15,43 @@
@Component
@RequiredArgsConstructor
public class ScheduleFactory {

private final DateScheduleFactory dateScheduleFactory;
private final TimeScheduleFactory timeScheduleFactory;

public Schedule create(List<DateScheduleView> dateScheduleViews) {
List<DateSchedule> dateSchedules = new ArrayList<>(dateScheduleViews.size());
for (DateScheduleView dateScheduleView : dateScheduleViews) {
DateSchedulePersist dateSchedulePersist = dateScheduleView.dateSchedulePersist();
DateSchedule dateSchedule = dateScheduleFactory.create(dateSchedulePersist);
List<TimeSchedule> timeSchedules = timeScheduleFactory.create(dateScheduleView.timeSchedulePersists());
dateSchedule.setTimeSchedules(timeSchedules);
dateSchedules.add(dateSchedule);
// DateSchedule dateSchedule = dateScheduleView.dateSchedule();
// List<TimeSchedule> timeSchedules = dateScheduleView.timeSchedules();
// dateSchedule.setTimeSchedules(timeSchedules);
// dateSchedules.add(dateSchedule);
}
return Schedule.builder()
.dateSchedules(dateSchedules)
.build();
}

public ScheduleResponseDto findResponse(Schedule schedule) {
return new ScheduleResponseDto(this.findDateResponses(schedule.dateSchedules));
public ScheduleResponseDto convertScheduleIntoResponse(Schedule schedule) {
return new ScheduleResponseDto(this.convertDateSchedulesIntoResponse(schedule.getDateSchedules()));
}

private List<DateScheduleResponseDto> findDateResponses(List<DateSchedule> dateSchedules) {
return dateSchedules.stream().map(this::findDateResponse).toList();
private List<DateScheduleResponseDto> convertDateSchedulesIntoResponse(List<DateSchedule> dateSchedules) {
return dateSchedules.stream().map(this::convertDateScheduleIntoResponse).toList();
}

private DateScheduleResponseDto findDateResponse(DateSchedule dateSchedule) {
private DateScheduleResponseDto convertDateScheduleIntoResponse(DateSchedule dateSchedule) {
return new ScheduleResponseDto.DateScheduleResponseDto(
dateSchedule.name,
dateSchedule.startDate,
dateSchedule.endDate,
this.findTimeResponses(dateSchedule.timeSchedules)
dateSchedule.getShowDate(),
this.convertTimeScheduleListIntoResponse(dateSchedule.getTimeSchedules())
);
}

private List<TimeScheduleResponseDto> findTimeResponses(List<TimeSchedule> timeSchedules) {
private List<TimeScheduleResponseDto> convertTimeScheduleListIntoResponse(List<TimeSchedule> timeSchedules) {
return timeSchedules.stream()
.map(this::findTimeResponse)
.map(this::convertTimeScheduleListIntoResponse)
.toList();
}

private TimeScheduleResponseDto findTimeResponse(TimeSchedule timeSchedule) {
private TimeScheduleResponseDto convertTimeScheduleListIntoResponse(TimeSchedule timeSchedule) {
return new TimeScheduleResponseDto(
timeSchedule.startTime,
timeSchedule.endTime
timeSchedule.getStartTime()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
package com.picketing.www.business.domain.schedule;

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

import com.picketing.www.persistence.table.BaseEntity;

import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder(access = AccessLevel.PROTECTED)
@Table(name = "TIME_SCHEDULE")
@Getter(AccessLevel.PROTECTED)
public class TimeSchedule extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "date_schedule_id")
private DateSchedule dateSchedule;

public class TimeSchedule {
final Long id;
final Long dateScheduleId;
final String name;
final LocalTime startTime;
final LocalTime endTime;
private LocalTime startTime;

@Builder
public TimeSchedule(Long id, Long dateScheduleId, String name, LocalTime startTime, LocalTime endTime) {
this.id = id;
this.dateScheduleId = dateScheduleId;
this.name = name;
this.startTime = startTime;
this.endTime = endTime;
}
@OneToMany(mappedBy = "timeSchedule")
private List<TimeScheduleSeatGrade> timeScheduleSeatGradeList = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package com.picketing.www.business.domain.schedule;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.picketing.www.persistence.table.schedule.TimeSchedulePersist;

@Component
public class TimeScheduleFactory {
public TimeSchedule create(TimeSchedulePersist timeSchedulePersist) {
return TimeSchedule.builder()
.id(timeSchedulePersist.id())
.startTime(timeSchedulePersist.startTime())
.endTime(timeSchedulePersist.endTime())
.build();
}
// public TimeSchedule create(TimeSchedulePersist timeSchedulePersist) {
// return TimeSchedule.builder()
// .id(timeSchedulePersist.id())
// .startTime(timeSchedulePersist.startTime())
// .endTime(timeSchedulePersist.endTime())
// .build();
// }

public List<TimeSchedule> create(List<TimeSchedulePersist> timeSchedulePersists) {
List<TimeSchedule> timeSchedules = new ArrayList<>();
for (TimeSchedulePersist timeSchedulePersist : timeSchedulePersists) {
timeSchedules.add(create(timeSchedulePersist));
}
return timeSchedules;
}
// public List<TimeSchedule> create(List<TimeSchedulePersist> timeSchedulePersists) {
// List<TimeSchedule> timeSchedules = new ArrayList<>();
// for (TimeSchedulePersist timeSchedulePersist : timeSchedulePersists) {
// timeSchedules.add(create(timeSchedulePersist));
// }
// return timeSchedules;
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.picketing.www.business.domain.schedule;

import com.picketing.www.business.domain.show.seat.SeatGrade;
import com.picketing.www.persistence.table.BaseEntity;

import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "TIME_SCHEDULE_SEAT_GRADE")
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class TimeScheduleSeatGrade extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "time_schedule_id")
private TimeSchedule timeSchedule;

@Enumerated(EnumType.STRING)
private SeatGrade seatGrade; // 현재 좌석 등급 및 가격이 모두 고정이므로, 같은 SeatGrade Enum 객체를 사용
}
Loading