diff --git a/src/main/java/com/beat/domain/performance/application/PerformanceService.java b/src/main/java/com/beat/domain/performance/application/PerformanceService.java index 1907a176..d2c85c44 100644 --- a/src/main/java/com/beat/domain/performance/application/PerformanceService.java +++ b/src/main/java/com/beat/domain/performance/application/PerformanceService.java @@ -36,6 +36,7 @@ import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -58,11 +59,17 @@ public PerformanceDetailResponse getPerformanceDetail(Long performanceId) { .orElseThrow(() -> new NotFoundException(PerformanceErrorCode.PERFORMANCE_NOT_FOUND)); List scheduleList = scheduleRepository.findByPerformanceId(performanceId).stream() - .map(schedule -> PerformanceDetailSchedule.of( - schedule.getId(), - schedule.getPerformanceDate(), - schedule.getScheduleNumber().name() - )).collect(Collectors.toList()); + .map(schedule -> { + int dueDate = scheduleService.calculateDueDate(schedule); + return PerformanceDetailSchedule.of( + schedule.getId(), + schedule.getPerformanceDate(), + schedule.getScheduleNumber().name(), + dueDate + ); + }).collect(Collectors.toList()); + + int minDueDate = scheduleService.getMinDueDate(scheduleRepository.findAllByPerformanceId(performanceId)); List castList = castRepository.findByPerformanceId(performanceId).stream() .map(cast -> PerformanceDetailCast.of( @@ -95,7 +102,8 @@ public PerformanceDetailResponse getPerformanceDetail(Long performanceId) { performance.getPerformanceContact(), performance.getPerformanceTeamName(), castList, - staffList + staffList, + minDueDate ); } @@ -107,12 +115,14 @@ public BookingPerformanceDetailResponse getBookingPerformanceDetail(Long perform List scheduleList = scheduleRepository.findByPerformanceId(performanceId).stream() .map(schedule -> { scheduleService.updateBookingStatus(schedule); + int dueDate = scheduleService.calculateDueDate(schedule); return BookingPerformanceDetailSchedule.of( schedule.getId(), schedule.getPerformanceDate(), schedule.getScheduleNumber().name(), scheduleService.getAvailableTicketCount(schedule), - schedule.isBooking() + schedule.isBooking(), + dueDate ); }).collect(Collectors.toList()); @@ -206,18 +216,40 @@ public MakerPerformanceResponse getMemberPerformances(Long memberId) { List performances = performanceRepository.findByUsersId(user.getId()); List performanceDetails = performances.stream() - .map(performance -> MakerPerformanceDetail.of( - performance.getId(), - performance.getGenre().name(), - performance.getPerformanceTitle(), - performance.getPosterImage(), - performance.getPerformancePeriod() - )) + .map(performance -> { + List schedules = scheduleRepository.findByPerformanceId(performance.getId()); + int minDueDate = scheduleService.getMinDueDate(schedules); + + return MakerPerformanceDetail.of( + performance.getId(), + performance.getGenre().name(), + performance.getPerformanceTitle(), + performance.getPosterImage(), + performance.getPerformancePeriod(), + minDueDate + ); + }) .collect(Collectors.toList()); - return MakerPerformanceResponse.of(user.getId(), performanceDetails); + // 양수 minDueDate 정렬 + List positiveDueDates = performanceDetails.stream() + .filter(detail -> detail.minDueDate() >= 0) + .sorted(Comparator.comparingInt(MakerPerformanceDetail::minDueDate)) + .collect(Collectors.toList()); + + // 음수 minDueDate 정렬 + List negativeDueDates = performanceDetails.stream() + .filter(detail -> detail.minDueDate() < 0) + .sorted(Comparator.comparingInt(MakerPerformanceDetail::minDueDate).reversed()) + .collect(Collectors.toList()); + + // 병합된 리스트 + positiveDueDates.addAll(negativeDueDates); + + return MakerPerformanceResponse.of(user.getId(), positiveDueDates); } + @Transactional public PerformanceEditResponse getPerformanceEdit(Long memberId, Long performanceId) { Member member = memberRepository.findById(memberId)