From 80136b351d3970efe4dac06655d396b96e6db102 Mon Sep 17 00:00:00 2001 From: hyerinhwang-sailin Date: Wed, 14 Aug 2024 00:39:21 +0900 Subject: [PATCH 1/9] =?UTF-8?q?[#172]=20feat(BeatApplication):=20cron=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20annotation=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/beat/BeatApplication.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/beat/BeatApplication.java b/src/main/java/com/beat/BeatApplication.java index 263f8261..4a4b8cb8 100644 --- a/src/main/java/com/beat/BeatApplication.java +++ b/src/main/java/com/beat/BeatApplication.java @@ -5,9 +5,11 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.FeignAutoConfiguration; +import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @EnableFeignClients +@EnableScheduling @ImportAutoConfiguration({FeignAutoConfiguration.class}) public class BeatApplication { From ca3c4b4ab8c6dca23c2306afd34dd35d5c15b9ec Mon Sep 17 00:00:00 2001 From: hyerinhwang-sailin Date: Wed, 14 Aug 2024 00:40:01 +0900 Subject: [PATCH 2/9] =?UTF-8?q?[#172]=20feat(Promotion):=20promotion=20ent?= =?UTF-8?q?ity=EC=97=90=20=EC=B6=94=EA=B0=80=EB=A1=9C=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beat/domain/promotion/domain/Promotion.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/beat/domain/promotion/domain/Promotion.java b/src/main/java/com/beat/domain/promotion/domain/Promotion.java index 445469ef..658c4f7b 100644 --- a/src/main/java/com/beat/domain/promotion/domain/Promotion.java +++ b/src/main/java/com/beat/domain/promotion/domain/Promotion.java @@ -20,19 +20,29 @@ public class Promotion { private String promotionPhoto; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "performance_id", nullable = false) + @JoinColumn(name = "performance_id", nullable = true) private Performance performance; + @Column(nullable = true) + private String redirectUrl; + + @Column(nullable = false) + private boolean isExternal; + @Builder - public Promotion(String promotionPhoto, Performance performance) { + public Promotion(String promotionPhoto, Performance performance, String redirectUrl, boolean isExternal) { this.promotionPhoto = promotionPhoto; this.performance = performance; + this.redirectUrl = redirectUrl; + this.isExternal = isExternal; } - public static Promotion create(String promotionPhoto, Performance performance) { + public static Promotion create(String promotionPhoto, Performance performance, String redirectUrl, boolean isExternal) { return Promotion.builder() .promotionPhoto(promotionPhoto) .performance(performance) + .redirectUrl(redirectUrl) + .isExternal(isExternal) .build(); } } From a952d27b3ad4da6b5536549f642dff4333422a86 Mon Sep 17 00:00:00 2001 From: hyerinhwang-sailin Date: Wed, 14 Aug 2024 00:41:01 +0900 Subject: [PATCH 3/9] =?UTF-8?q?[#172]=20feat(PromotionService):=20?= =?UTF-8?q?=EC=A7=80=EB=82=98=EA=B0=84=20=EA=B3=B5=EC=97=B0=EC=97=90=20?= =?UTF-8?q?=ED=95=B4=EB=8B=B9=ED=95=98=EB=8A=94=20promotion=20=EC=BA=90?= =?UTF-8?q?=EB=9F=AC=EC=85=80=20=EC=82=AD=EC=A0=9C=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/PromotionService.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/com/beat/domain/promotion/application/PromotionService.java diff --git a/src/main/java/com/beat/domain/promotion/application/PromotionService.java b/src/main/java/com/beat/domain/promotion/application/PromotionService.java new file mode 100644 index 00000000..551231a7 --- /dev/null +++ b/src/main/java/com/beat/domain/promotion/application/PromotionService.java @@ -0,0 +1,43 @@ +package com.beat.domain.promotion.application; + +import com.beat.domain.performance.domain.Performance; +import com.beat.domain.promotion.dao.PromotionRepository; +import com.beat.domain.promotion.domain.Promotion; +import com.beat.domain.schedule.application.ScheduleService; +import com.beat.domain.schedule.dao.ScheduleRepository; +import com.beat.domain.schedule.domain.Schedule; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class PromotionService { + + private final PromotionRepository promotionRepository; + private final ScheduleRepository scheduleRepository; + private final ScheduleService scheduleService; + + @Scheduled(cron = "1 0 0 * * ?") + @Transactional + public void checkAndDeleteInvalidPromotions() { + List promotions = promotionRepository.findAll(); + + for (Promotion promotion : promotions) { + if (promotion.getPerformance() != null) { + Performance performance = promotion.getPerformance(); + + List schedules = scheduleRepository.findByPerformanceId(performance.getId()); + int minDueDate = scheduleService.getMinDueDate(schedules); + + // MinDueDate가 음수일 경우 Promotion 삭제 + if (minDueDate < 0) { + promotionRepository.delete(promotion); + } + } + } + } +} From ee2cb4e3d7b36605c9b9222162073d797ed975ca Mon Sep 17 00:00:00 2001 From: hyerinhwang-sailin Date: Wed, 14 Aug 2024 00:42:06 +0900 Subject: [PATCH 4/9] =?UTF-8?q?[#172]=20feat(PerformanceDetailResponse):?= =?UTF-8?q?=20=EA=B3=B5=EC=97=B0=20=EC=83=81=EC=84=B8=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20response=EC=97=90=20minDueDate=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/PerformanceDetailResponse.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/beat/domain/performance/application/dto/PerformanceDetailResponse.java b/src/main/java/com/beat/domain/performance/application/dto/PerformanceDetailResponse.java index a8f48a30..b095d81a 100644 --- a/src/main/java/com/beat/domain/performance/application/dto/PerformanceDetailResponse.java +++ b/src/main/java/com/beat/domain/performance/application/dto/PerformanceDetailResponse.java @@ -17,7 +17,8 @@ public record PerformanceDetailResponse( String performanceContact, String performanceTeamName, List castList, - List staffList + List staffList, + int minDueDate ) { public static PerformanceDetailResponse of( Long performanceId, @@ -34,10 +35,26 @@ public static PerformanceDetailResponse of( String performanceContact, String performanceTeamName, List castList, - List staffList + List staffList, + int minDueDate ) { - return new PerformanceDetailResponse(performanceId, performanceTitle, performancePeriod, scheduleList, ticketPrice, genre, posterImage, runningTime, performanceVenue, performanceDescription, performanceAttentionNote, performanceContact, performanceTeamName, castList, staffList); + return new PerformanceDetailResponse( + performanceId, + performanceTitle, + performancePeriod, + scheduleList, + ticketPrice, + genre, + posterImage, + runningTime, + performanceVenue, + performanceDescription, + performanceAttentionNote, + performanceContact, + performanceTeamName, + castList, + staffList, + minDueDate + ); } - - } From 1f4fe879a063750335e61518efca383278cfeb16 Mon Sep 17 00:00:00 2001 From: hyerinhwang-sailin Date: Wed, 14 Aug 2024 00:42:26 +0900 Subject: [PATCH 5/9] =?UTF-8?q?[#172]=20feat(PerformanceDetailResponse):?= =?UTF-8?q?=20=EA=B3=B5=EC=97=B0=20=EC=83=81=EC=84=B8=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20response=EC=97=90=20schedule=EB=B3=84?= =?UTF-8?q?=20dueDate=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dto/PerformanceDetailSchedule.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/beat/domain/performance/application/dto/PerformanceDetailSchedule.java b/src/main/java/com/beat/domain/performance/application/dto/PerformanceDetailSchedule.java index dcfe54c7..ce0808a0 100644 --- a/src/main/java/com/beat/domain/performance/application/dto/PerformanceDetailSchedule.java +++ b/src/main/java/com/beat/domain/performance/application/dto/PerformanceDetailSchedule.java @@ -5,9 +5,10 @@ public record PerformanceDetailSchedule( Long scheduleId, LocalDateTime performanceDate, - String scheduleNumber + String scheduleNumber, + int dueDate ) { - public static PerformanceDetailSchedule of(Long scheduleId, LocalDateTime performanceDate, String scheduleNumber) { - return new PerformanceDetailSchedule(scheduleId, performanceDate, scheduleNumber); + public static PerformanceDetailSchedule of(Long scheduleId, LocalDateTime performanceDate, String scheduleNumber, int dueDate) { + return new PerformanceDetailSchedule(scheduleId, performanceDate, scheduleNumber, dueDate); } } From 971992e479f4c0da79e94fb86208dc65132f12c5 Mon Sep 17 00:00:00 2001 From: hyerinhwang-sailin Date: Wed, 14 Aug 2024 00:43:14 +0900 Subject: [PATCH 6/9] =?UTF-8?q?[#172]=20feat(BookingPerformanceDetailSched?= =?UTF-8?q?ule):=20=EC=98=88=EB=A7=A4=ED=95=98=EA=B8=B0=EC=97=90=20?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EA=B3=B5=EC=97=B0=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20response?= =?UTF-8?q?=EC=97=90=20schedule=EB=B3=84=20dueDate=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dto/BookingPerformanceDetailSchedule.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/beat/domain/performance/application/dto/BookingPerformanceDetailSchedule.java b/src/main/java/com/beat/domain/performance/application/dto/BookingPerformanceDetailSchedule.java index 0cbe3616..3fedccf6 100644 --- a/src/main/java/com/beat/domain/performance/application/dto/BookingPerformanceDetailSchedule.java +++ b/src/main/java/com/beat/domain/performance/application/dto/BookingPerformanceDetailSchedule.java @@ -7,10 +7,11 @@ public record BookingPerformanceDetailSchedule( LocalDateTime performanceDate, String scheduleNumber, int availableTicketCount, - boolean isBooking + boolean isBooking, + int dueDate ) { - public static BookingPerformanceDetailSchedule of(Long scheduleId, LocalDateTime performanceDate, String scheduleNumber, int availableTicketCount, boolean isBooking) { - return new BookingPerformanceDetailSchedule(scheduleId, performanceDate, scheduleNumber, availableTicketCount, isBooking); + public static BookingPerformanceDetailSchedule of(Long scheduleId, LocalDateTime performanceDate, String scheduleNumber, int availableTicketCount, boolean isBooking, int dueDate) { + return new BookingPerformanceDetailSchedule(scheduleId, performanceDate, scheduleNumber, availableTicketCount, isBooking, dueDate); } } From ac5a6a7933bdb4f9a6761530f339c9063ae26670 Mon Sep 17 00:00:00 2001 From: hyerinhwang-sailin Date: Wed, 14 Aug 2024 00:43:50 +0900 Subject: [PATCH 7/9] =?UTF-8?q?[#172]=20feat(MakerPerformanceDetail):=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=ED=95=9C=20=EA=B3=B5=EC=97=B0=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20response=EC=97=90=20MinDueDate=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dto/MakerPerformanceDetail.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/beat/domain/performance/application/dto/MakerPerformanceDetail.java b/src/main/java/com/beat/domain/performance/application/dto/MakerPerformanceDetail.java index 21dcaa61..97ba91a0 100644 --- a/src/main/java/com/beat/domain/performance/application/dto/MakerPerformanceDetail.java +++ b/src/main/java/com/beat/domain/performance/application/dto/MakerPerformanceDetail.java @@ -5,14 +5,16 @@ public record MakerPerformanceDetail( String genre, String performanceTitle, String posterImage, - String performancePeriod + String performancePeriod, + int minDueDate ) { public static MakerPerformanceDetail of( Long performanceId, String genre, String performanceTitle, String posterImage, - String performancePeriod) { - return new MakerPerformanceDetail(performanceId, genre, performanceTitle, posterImage, performancePeriod); + String performancePeriod, + int minDueDate) { // minDueDate 매개변수 추가 + return new MakerPerformanceDetail(performanceId, genre, performanceTitle, posterImage, performancePeriod, minDueDate); } } From 7d88debb6b13868267a6ce1ed8e114d473a6d0eb Mon Sep 17 00:00:00 2001 From: hyerinhwang-sailin Date: Wed, 14 Aug 2024 00:44:52 +0900 Subject: [PATCH 8/9] =?UTF-8?q?[#172]=20feat(PerformanceService):=20respon?= =?UTF-8?q?se=EC=97=90=20=EC=B6=94=EA=B0=80=ED=95=9C=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=20=EB=B0=98=EC=98=81=20=EB=B0=8F=20=EB=93=B1=EB=A1=9D=ED=95=9C?= =?UTF-8?q?=20=EA=B3=B5=EC=97=B0=20=EC=A1=B0=ED=9A=8C=20=EC=A0=95=EB=A0=AC?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/PerformanceService.java | 62 ++++++++++++++----- 1 file changed, 47 insertions(+), 15 deletions(-) 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) From 94bf32b146e223f665162e39fac8a058bf417e49 Mon Sep 17 00:00:00 2001 From: hyerinhwang-sailin Date: Fri, 16 Aug 2024 16:16:18 +0900 Subject: [PATCH 9/9] =?UTF-8?q?[#172]=20refactor(PromotionService):=20chec?= =?UTF-8?q?kAndDeleteInvalidPromotions=20=EC=84=B1=EB=8A=A5=20=EB=B0=8F=20?= =?UTF-8?q?=ED=99=95=EC=9E=A5=EC=84=B1=20=EA=B3=A0=EB=A0=A4=ED=95=9C=20ref?= =?UTF-8?q?actor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/application/PromotionService.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/beat/domain/promotion/application/PromotionService.java b/src/main/java/com/beat/domain/promotion/application/PromotionService.java index 551231a7..70d86270 100644 --- a/src/main/java/com/beat/domain/promotion/application/PromotionService.java +++ b/src/main/java/com/beat/domain/promotion/application/PromotionService.java @@ -27,16 +27,17 @@ public void checkAndDeleteInvalidPromotions() { List promotions = promotionRepository.findAll(); for (Promotion promotion : promotions) { - if (promotion.getPerformance() != null) { - Performance performance = promotion.getPerformance(); + Performance performance = promotion.getPerformance(); - List schedules = scheduleRepository.findByPerformanceId(performance.getId()); - int minDueDate = scheduleService.getMinDueDate(schedules); + if (performance == null) { + return; + } + + List schedules = scheduleRepository.findByPerformanceId(performance.getId()); + int minDueDate = scheduleService.getMinDueDate(schedules); - // MinDueDate가 음수일 경우 Promotion 삭제 - if (minDueDate < 0) { - promotionRepository.delete(promotion); - } + if (minDueDate < 0) { + promotionRepository.delete(promotion); } } }