Skip to content

Commit

Permalink
[#172] feat(PromotionService): 지나간 공연에 해당하는 promotion 캐러셀 삭제하는 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
hyerinhwang-sailin committed Aug 13, 2024
1 parent ca3c4b4 commit a952d27
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Promotion> promotions = promotionRepository.findAll();

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

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

// MinDueDate가 음수일 경우 Promotion 삭제
if (minDueDate < 0) {
promotionRepository.delete(promotion);
}
}
}
}
}

0 comments on commit a952d27

Please sign in to comment.