Skip to content

Commit

Permalink
Merge pull request #22 from softeerbootcamp4th/fix/eckrin
Browse files Browse the repository at this point in the history
[Fix] 이벤트 당첨자 수 스케줄링 로직 수정
  • Loading branch information
eckrin authored Aug 14, 2024
2 parents e75a6ea + 5d1adfa commit 3eb767b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.softeer.podoarrival.event.model.entity.EventReward;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface EventRewardRepository extends JpaRepository<EventReward, Long> {
int countByEvent(Event event);
List<EventReward> findAllByEvent(Event event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.softeer.podoarrival.event.exception.EventTypeNotExistsException;
import com.softeer.podoarrival.event.model.entity.Event;
import com.softeer.podoarrival.event.model.entity.EventReward;
import com.softeer.podoarrival.event.model.entity.EventType;
import com.softeer.podoarrival.event.repository.EventRepository;
import com.softeer.podoarrival.event.repository.EventRewardRepository;
Expand All @@ -15,6 +16,7 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
* 선착순 이벤트의 당첨자 수를 세팅하는 스케줄러
Expand Down Expand Up @@ -42,10 +44,14 @@ public void setEventArrivalCount() {
EventType eventType = eventTypeRepository.findById(1L).orElseThrow(() -> new EventTypeNotExistsException("이벤트 타입이 존재하지 않습니다."));
Event findEvent = eventRepository.findFirstByEventTypeAndStartAtBetween(eventType, startOfDay, endOfDay);

// 찾은 이벤트에 해당하는 reword개수 조회
int rewordCount = eventRewardRepository.countByEvent(findEvent);
// 찾은 이벤트에 해당하는 reward개수 조회
int rewardCount = 0;
List<EventReward> eventRewards = eventRewardRepository.findAllByEvent(findEvent);
for (EventReward eventReward : eventRewards) {
rewardCount += eventReward.getNumWinners();
}

ArrivalEventReleaseServiceRedisImpl.setMaxArrival(rewordCount);
ArrivalEventReleaseServiceJavaImpl.setMaxArrival(rewordCount);
ArrivalEventReleaseServiceRedisImpl.setMaxArrival(rewardCount);
ArrivalEventReleaseServiceJavaImpl.setMaxArrival(rewardCount);
}
}

0 comments on commit 3eb767b

Please sign in to comment.