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

[feat] #172 - 캐러셀 response에 필드 추가 #176

Merged
merged 11 commits into from
Aug 16, 2024
Merged
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
2 changes: 2 additions & 0 deletions src/main/java/com/beat/BeatApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -58,11 +59,17 @@ public PerformanceDetailResponse getPerformanceDetail(Long performanceId) {
.orElseThrow(() -> new NotFoundException(PerformanceErrorCode.PERFORMANCE_NOT_FOUND));

List<PerformanceDetailSchedule> 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<PerformanceDetailCast> castList = castRepository.findByPerformanceId(performanceId).stream()
.map(cast -> PerformanceDetailCast.of(
Expand Down Expand Up @@ -95,7 +102,8 @@ public PerformanceDetailResponse getPerformanceDetail(Long performanceId) {
performance.getPerformanceContact(),
performance.getPerformanceTeamName(),
castList,
staffList
staffList,
minDueDate
);
}

Expand All @@ -107,12 +115,14 @@ public BookingPerformanceDetailResponse getBookingPerformanceDetail(Long perform
List<BookingPerformanceDetailSchedule> 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());

Expand Down Expand Up @@ -190,7 +200,9 @@ private List<HomePromotionDetail> getPromotions() {
.map(promotion -> HomePromotionDetail.of(
promotion.getId(),
promotion.getPromotionPhoto(),
promotion.getPerformance().getId()
promotion.getPerformance().getId(),
promotion.getRedirectUrl(),
promotion.isExternal()
))
.collect(Collectors.toList());
}
Expand All @@ -206,18 +218,40 @@ public MakerPerformanceResponse getMemberPerformances(Long memberId) {
List<Performance> performances = performanceRepository.findByUsersId(user.getId());

List<MakerPerformanceDetail> performanceDetails = performances.stream()
.map(performance -> MakerPerformanceDetail.of(
performance.getId(),
performance.getGenre().name(),
performance.getPerformanceTitle(),
performance.getPosterImage(),
performance.getPerformancePeriod()
))
.map(performance -> {
List<Schedule> 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<MakerPerformanceDetail> positiveDueDates = performanceDetails.stream()
.filter(detail -> detail.minDueDate() >= 0)
.sorted(Comparator.comparingInt(MakerPerformanceDetail::minDueDate))
.collect(Collectors.toList());

// 음수 minDueDate 정렬
List<MakerPerformanceDetail> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public record PerformanceDetailResponse(
String performanceContact,
String performanceTeamName,
List<PerformanceDetailCast> castList,
List<PerformanceDetailStaff> staffList
List<PerformanceDetailStaff> staffList,
int minDueDate
) {
public static PerformanceDetailResponse of(
Long performanceId,
Expand All @@ -34,10 +35,26 @@ public static PerformanceDetailResponse of(
String performanceContact,
String performanceTeamName,
List<PerformanceDetailCast> castList,
List<PerformanceDetailStaff> staffList
List<PerformanceDetailStaff> 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
);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
public record HomePromotionDetail(
Long promotionId,
String promotionPhoto,
Long performanceId
Long performanceId,
String redirectUrl,
boolean isExternal
) {
public static HomePromotionDetail of(Long promotionId, String promotionPhoto, Long performanceId) {
return new HomePromotionDetail(promotionId, promotionPhoto, performanceId);
public static HomePromotionDetail of(Long promotionId, String promotionPhoto, Long performanceId, String redirectUrl, boolean isExternal) {
return new HomePromotionDetail(promotionId, promotionPhoto, performanceId, redirectUrl, isExternal);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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<Promotion> promotions = promotionRepository.findAll();

for (Promotion promotion : promotions) {
Performance performance = promotion.getPerformance();

if (performance == null) {
return;
}

List<Schedule> schedules = scheduleRepository.findByPerformanceId(performance.getId());
int minDueDate = scheduleService.getMinDueDate(schedules);

if (minDueDate < 0) {
promotionRepository.delete(promotion);
}
}
}
}
16 changes: 13 additions & 3 deletions src/main/java/com/beat/domain/promotion/domain/Promotion.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Loading