diff --git a/build.gradle b/build.gradle index 9f8618d..dcbfbd4 100644 --- a/build.gradle +++ b/build.gradle @@ -91,6 +91,8 @@ dependencies { //redission implementation 'org.redisson:redisson-spring-boot-starter:3.33.0' implementation "org.redisson:redisson-spring-data-27:3.33.0" + //webflux + implementation 'org.springframework.boot:spring-boot-starter-webflux' } tasks.named('test') { diff --git a/src/main/java/com/softeer/podoarrival/event/controller/ArrivalEventController.java b/src/main/java/com/softeer/podoarrival/event/controller/ArrivalEventController.java index 61328fd..e527cc9 100644 --- a/src/main/java/com/softeer/podoarrival/event/controller/ArrivalEventController.java +++ b/src/main/java/com/softeer/podoarrival/event/controller/ArrivalEventController.java @@ -3,6 +3,7 @@ import com.softeer.podoarrival.common.response.CommonResponse; import com.softeer.podoarrival.event.exception.AsyncRequestExecuteException; +import com.softeer.podoarrival.event.exception.EventClosedException; import com.softeer.podoarrival.event.exception.ExistingUserException; import com.softeer.podoarrival.event.model.dto.ArrivalApplicationResponseDto; import com.softeer.podoarrival.event.service.ArrivalEventService; @@ -35,6 +36,8 @@ public CompletableFuture> arrivalE // 내부 예외 처리 if(ex.getCause() instanceof ExistingUserException) { throw new ExistingUserException("[비동기 에러] 유저가 이미 존재합니다."); + } else if(ex.getCause() instanceof EventClosedException){ + throw new EventClosedException(ex.getMessage()); } else { log.error("Exception occurred while arrival application", ex); throw new AsyncRequestExecuteException("[비동기 에러] 선착순 요청 중 서버 오류 발생"); diff --git a/src/main/java/com/softeer/podoarrival/event/scheduler/ArrivalEventInformationScheduler.java b/src/main/java/com/softeer/podoarrival/event/scheduler/ArrivalEventInformationScheduler.java index f23a693..416ee0c 100644 --- a/src/main/java/com/softeer/podoarrival/event/scheduler/ArrivalEventInformationScheduler.java +++ b/src/main/java/com/softeer/podoarrival/event/scheduler/ArrivalEventInformationScheduler.java @@ -78,7 +78,7 @@ public void setArrivalEventInformation() { ArrivalEventReleaseServiceRedisImpl.setMaxArrival(rewardCount); ArrivalEventReleaseServiceJavaImpl.setMaxArrival(rewardCount); - ArrivalEventReleaseServiceRedisImpl.setStartTime(repeatTime); - ArrivalEventReleaseServiceJavaImpl.setStartTime(repeatTime); + ArrivalEventReleaseServiceRedisImpl.setStartTime(LocalDateTime.of(LocalDate.now(), repeatTime)); + ArrivalEventReleaseServiceJavaImpl.setStartTime(LocalDateTime.of(LocalDate.now(), repeatTime)); } } diff --git a/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseService.java b/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseService.java index a256e00..524287c 100644 --- a/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseService.java +++ b/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseService.java @@ -3,9 +3,12 @@ import com.softeer.podoarrival.event.model.dto.ArrivalApplicationResponseDto; import com.softeer.podoarrival.security.AuthInfo; +import java.time.LocalDateTime; import java.util.concurrent.CompletableFuture; public interface ArrivalEventReleaseService { CompletableFuture applyEvent(AuthInfo authInfo); + + public LocalDateTime getStartTime(); } diff --git a/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseServiceJavaImpl.java b/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseServiceJavaImpl.java index 9c76729..3cf82f9 100644 --- a/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseServiceJavaImpl.java +++ b/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseServiceJavaImpl.java @@ -14,6 +14,8 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.LocalTime; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; @@ -28,7 +30,7 @@ public class ArrivalEventReleaseServiceJavaImpl implements ArrivalEventReleaseSe private static int MAX_ARRIVAL = 100; // default private boolean CHECK = false; - private static LocalTime START_TIME = LocalTime.of(0, 0); + private static LocalDateTime START_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(0, 0)); private static boolean START_DATE = true; private static AtomicInteger count = new AtomicInteger(1); @@ -43,7 +45,7 @@ public class ArrivalEventReleaseServiceJavaImpl implements ArrivalEventReleaseSe public CompletableFuture applyEvent(AuthInfo authInfo) { return CompletableFuture.supplyAsync(() -> { if(!START_DATE) throw new EventClosedException("이벤트 요일이 아닙니다."); - if(LocalTime.now().isBefore(START_TIME)) throw new EventClosedException("이벤트 시간이 아닙니다."); + if(LocalDateTime.now().isBefore(START_TIME)) throw new EventClosedException("이벤트 시간이 아닙니다."); if(CHECK){ return new ArrivalApplicationResponseDto(false, authInfo.getName(), authInfo.getPhoneNum(), -1); @@ -69,6 +71,7 @@ public CompletableFuture applyEvent(AuthInfo auth return new ArrivalApplicationResponseDto(true, authInfo.getName(), authInfo.getPhoneNum(), grade); } else { CHECK = true; + START_TIME = LocalDateTime.of(LocalDate.now().plusDays(1), START_TIME.toLocalTime()); return new ArrivalApplicationResponseDto(false, authInfo.getName(), authInfo.getPhoneNum(), grade); } }); @@ -78,7 +81,7 @@ public static void setMaxArrival(int val) { MAX_ARRIVAL = val; } - public static void setStartTime(LocalTime val) { + public static void setStartTime(LocalDateTime val) { START_TIME = val; } @@ -91,7 +94,11 @@ public static int getMaxArrival() { } - public static LocalTime getStartTime() { + public LocalDateTime getStartTime() { + return START_TIME; + } + + public static LocalDateTime getStartTimeStatic(){ return START_TIME; } diff --git a/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseServiceRedisImpl.java b/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseServiceRedisImpl.java index 872b08f..d0dedbd 100644 --- a/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseServiceRedisImpl.java +++ b/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseServiceRedisImpl.java @@ -18,6 +18,7 @@ import org.springframework.stereotype.Service; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.LocalTime; import java.util.concurrent.CompletableFuture; @@ -34,7 +35,7 @@ public class ArrivalEventReleaseServiceRedisImpl implements ArrivalEventReleaseS private final String ARRIVAL_SET = "arrivalset"; private boolean CHECK = false; private static int MAX_ARRIVAL = 100; // default - private static LocalTime START_TIME = LocalTime.of(0, 0); + private static LocalDateTime START_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(0, 0)); private static boolean START_DATE = true; /** @@ -49,7 +50,7 @@ public CompletableFuture applyEvent(AuthInfo auth String redisKey = LocalDate.now() + ARRIVAL_SET; if(!START_DATE) throw new EventClosedException("이벤트 요일이 아닙니다."); - if(LocalTime.now().isBefore(START_TIME)) throw new EventClosedException("이벤트 시간이 아닙니다."); + if(LocalDateTime.now().isBefore(START_TIME)) throw new EventClosedException("이벤트 시간이 아닙니다."); if(CHECK){ return new ArrivalApplicationResponseDto(false, authInfo.getName(), authInfo.getPhoneNum(), -1); @@ -80,6 +81,7 @@ public CompletableFuture applyEvent(AuthInfo auth return new ArrivalApplicationResponseDto(true, authInfo.getName(), authInfo.getPhoneNum(), grade); } else { CHECK = true; + START_TIME = LocalDateTime.of(LocalDate.now().plusDays(1), START_TIME.toLocalTime()); return new ArrivalApplicationResponseDto(false, authInfo.getName(), authInfo.getPhoneNum(), grade); } }); @@ -89,7 +91,7 @@ public static void setMaxArrival(int val) { MAX_ARRIVAL = val; } - public static void setStartTime(LocalTime val) { + public static void setStartTime(LocalDateTime val) { START_TIME = val; } @@ -101,7 +103,11 @@ public static int getMaxArrival() { return MAX_ARRIVAL; } - public static LocalTime getStartTime() { + public LocalDateTime getStartTime() { + return START_TIME; + } + + public static LocalDateTime getStartTimeStatic(){ return START_TIME; } diff --git a/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventService.java b/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventService.java index d35e739..d59264d 100644 --- a/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventService.java +++ b/src/main/java/com/softeer/podoarrival/event/service/ArrivalEventService.java @@ -8,7 +8,7 @@ import reactor.core.publisher.Flux; import java.time.Duration; -import java.time.LocalTime; +import java.time.LocalDateTime; import java.util.concurrent.CompletableFuture; @Slf4j @@ -37,8 +37,8 @@ public Flux streamLeftSecondsToEventTime() { Flux.just(0L), // Emit initial value immediately Flux.interval(Duration.ofSeconds(20))) .map(sequence -> { - LocalTime startTime = ArrivalEventReleaseServiceJavaImpl.getStartTime(); - long seconds = Duration.between(LocalTime.now(), startTime).getSeconds(); + LocalDateTime startTime = arrivalEventReleaseServiceRedisImpl.getStartTime(); + long seconds = Duration.between(LocalDateTime.now(), startTime).getSeconds(); return Math.max(seconds, 0); }); } diff --git a/src/test/java/com/softeer/podoarrival/unit/scheduler/ArrivalEventInformationTest.java b/src/test/java/com/softeer/podoarrival/unit/scheduler/ArrivalEventInformationTest.java index 37644c6..a377765 100644 --- a/src/test/java/com/softeer/podoarrival/unit/scheduler/ArrivalEventInformationTest.java +++ b/src/test/java/com/softeer/podoarrival/unit/scheduler/ArrivalEventInformationTest.java @@ -48,9 +48,9 @@ public void setArrivalEventCountSuccess_Data_Exists() { .isEqualTo(60); Assertions.assertThat(ArrivalEventReleaseServiceJavaImpl.getMaxArrival()) .isEqualTo(60); - Assertions.assertThat(ArrivalEventReleaseServiceRedisImpl.getStartTime()) + Assertions.assertThat(ArrivalEventReleaseServiceRedisImpl.getStartTimeStatic()) .isEqualTo(LocalTime.of(15, 0)); - Assertions.assertThat(ArrivalEventReleaseServiceJavaImpl.getStartTime()) + Assertions.assertThat(ArrivalEventReleaseServiceJavaImpl.getStartTimeStatic()) .isEqualTo(LocalTime.of(15, 0)); }