Skip to content

Commit

Permalink
[#299] refactor(PromotionSchedulerService): 캐러셀 삭제 로직 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
hyerinhwang-sailin committed Jan 3, 2025
1 parent c8140c3 commit 099a7a6
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
Expand All @@ -35,7 +36,7 @@ public void checkAndDeleteInvalidPromotions() {
List<Long> promotionIdsToDelete = promotionRepository.findAll().stream()
.filter(this::isInvalidPromotion)
.map(Promotion::getId)
.collect(Collectors.toList());
.toList();

if (promotionIdsToDelete.isEmpty()) {
return;
Expand All @@ -60,10 +61,10 @@ private void reassignCarouselNumbers() {
List<Promotion> remainingPromotions = promotionRepository.findAll();
remainingPromotions.sort(Comparator.comparing(promotion -> promotion.getCarouselNumber().getNumber()));

CarouselNumber[] carouselNumbers = CarouselNumber.values();
List<CarouselNumber> carouselNumbers = Arrays.asList(CarouselNumber.values());
for (int i = 0; i < remainingPromotions.size(); i++) {
Promotion promotion = remainingPromotions.get(i);
promotion.updateCarouselNumber(carouselNumbers[i]);
promotion.updateCarouselNumber(carouselNumbers.get(i));
}

promotionRepository.saveAll(remainingPromotions);
Expand Down

0 comments on commit 099a7a6

Please sign in to comment.