Skip to content

Commit e79644c

Browse files
committed
feat: 선착순 종료시 이벤트 시간이 다시 설정되게끔 수정
- ArrivalEventReleaseService interface에 getStartTime method 추가 - 기존에 있던 static method도 이름을 변경하여 유지 - start time을 local date가 아닌 localDatetimed으로 저장하게끔 수정
1 parent d38a0ba commit e79644c

File tree

6 files changed

+31
-15
lines changed

6 files changed

+31
-15
lines changed

Diff for: src/main/java/com/softeer/podoarrival/event/scheduler/ArrivalEventInformationScheduler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void setArrivalEventInformation() {
7878
ArrivalEventReleaseServiceRedisImpl.setMaxArrival(rewardCount);
7979
ArrivalEventReleaseServiceJavaImpl.setMaxArrival(rewardCount);
8080

81-
ArrivalEventReleaseServiceRedisImpl.setStartTime(repeatTime);
82-
ArrivalEventReleaseServiceJavaImpl.setStartTime(repeatTime);
81+
ArrivalEventReleaseServiceRedisImpl.setStartTime(LocalDateTime.of(LocalDate.now(), repeatTime));
82+
ArrivalEventReleaseServiceJavaImpl.setStartTime(LocalDateTime.of(LocalDate.now(), repeatTime));
8383
}
8484
}

Diff for: src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseService.java

+3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import com.softeer.podoarrival.event.model.dto.ArrivalApplicationResponseDto;
44
import com.softeer.podoarrival.security.AuthInfo;
55

6+
import java.time.LocalDateTime;
67
import java.util.concurrent.CompletableFuture;
78

89
public interface ArrivalEventReleaseService {
910

1011
CompletableFuture<ArrivalApplicationResponseDto> applyEvent(AuthInfo authInfo);
12+
13+
public LocalDateTime getStartTime();
1114
}

Diff for: src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseServiceJavaImpl.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.springframework.scheduling.annotation.Async;
1515
import org.springframework.stereotype.Service;
1616

17+
import java.time.LocalDate;
18+
import java.time.LocalDateTime;
1719
import java.time.LocalTime;
1820
import java.util.concurrent.CompletableFuture;
1921
import java.util.concurrent.ConcurrentHashMap;
@@ -28,7 +30,7 @@ public class ArrivalEventReleaseServiceJavaImpl implements ArrivalEventReleaseSe
2830

2931
private static int MAX_ARRIVAL = 100; // default
3032
private boolean CHECK = false;
31-
private static LocalTime START_TIME = LocalTime.of(0, 0);
33+
private static LocalDateTime START_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(0, 0));
3234
private static boolean START_DATE = true;
3335

3436
private static AtomicInteger count = new AtomicInteger(1);
@@ -43,7 +45,7 @@ public class ArrivalEventReleaseServiceJavaImpl implements ArrivalEventReleaseSe
4345
public CompletableFuture<ArrivalApplicationResponseDto> applyEvent(AuthInfo authInfo) {
4446
return CompletableFuture.supplyAsync(() -> {
4547
if(!START_DATE) throw new EventClosedException("이벤트 요일이 아닙니다.");
46-
if(LocalTime.now().isBefore(START_TIME)) throw new EventClosedException("이벤트 시간이 아닙니다.");
48+
if(LocalDateTime.now().isBefore(START_TIME)) throw new EventClosedException("이벤트 시간이 아닙니다.");
4749

4850
if(CHECK){
4951
return new ArrivalApplicationResponseDto(false, authInfo.getName(), authInfo.getPhoneNum(), -1);
@@ -69,6 +71,7 @@ public CompletableFuture<ArrivalApplicationResponseDto> applyEvent(AuthInfo auth
6971
return new ArrivalApplicationResponseDto(true, authInfo.getName(), authInfo.getPhoneNum(), grade);
7072
} else {
7173
CHECK = true;
74+
START_TIME = LocalDateTime.of(LocalDate.now().plusDays(1), START_TIME.toLocalTime());
7275
return new ArrivalApplicationResponseDto(false, authInfo.getName(), authInfo.getPhoneNum(), grade);
7376
}
7477
});
@@ -78,7 +81,7 @@ public static void setMaxArrival(int val) {
7881
MAX_ARRIVAL = val;
7982
}
8083

81-
public static void setStartTime(LocalTime val) {
84+
public static void setStartTime(LocalDateTime val) {
8285
START_TIME = val;
8386
}
8487

@@ -91,7 +94,11 @@ public static int getMaxArrival() {
9194
}
9295

9396

94-
public static LocalTime getStartTime() {
97+
public LocalDateTime getStartTime() {
98+
return START_TIME;
99+
}
100+
101+
public static LocalDateTime getStartTimeStatic(){
95102
return START_TIME;
96103
}
97104

Diff for: src/main/java/com/softeer/podoarrival/event/service/ArrivalEventReleaseServiceRedisImpl.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.springframework.stereotype.Service;
1919

2020
import java.time.LocalDate;
21+
import java.time.LocalDateTime;
2122
import java.time.LocalTime;
2223
import java.util.concurrent.CompletableFuture;
2324

@@ -34,7 +35,7 @@ public class ArrivalEventReleaseServiceRedisImpl implements ArrivalEventReleaseS
3435
private final String ARRIVAL_SET = "arrivalset";
3536
private boolean CHECK = false;
3637
private static int MAX_ARRIVAL = 100; // default
37-
private static LocalTime START_TIME = LocalTime.of(0, 0);
38+
private static LocalDateTime START_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(0, 0));
3839
private static boolean START_DATE = true;
3940

4041
/**
@@ -49,7 +50,7 @@ public CompletableFuture<ArrivalApplicationResponseDto> applyEvent(AuthInfo auth
4950
String redisKey = LocalDate.now() + ARRIVAL_SET;
5051

5152
if(!START_DATE) throw new EventClosedException("이벤트 요일이 아닙니다.");
52-
if(LocalTime.now().isBefore(START_TIME)) throw new EventClosedException("이벤트 시간이 아닙니다.");
53+
if(LocalDateTime.now().isBefore(START_TIME)) throw new EventClosedException("이벤트 시간이 아닙니다.");
5354

5455
if(CHECK){
5556
return new ArrivalApplicationResponseDto(false, authInfo.getName(), authInfo.getPhoneNum(), -1);
@@ -80,6 +81,7 @@ public CompletableFuture<ArrivalApplicationResponseDto> applyEvent(AuthInfo auth
8081
return new ArrivalApplicationResponseDto(true, authInfo.getName(), authInfo.getPhoneNum(), grade);
8182
} else {
8283
CHECK = true;
84+
START_TIME = LocalDateTime.of(LocalDate.now().plusDays(1), START_TIME.toLocalTime());
8385
return new ArrivalApplicationResponseDto(false, authInfo.getName(), authInfo.getPhoneNum(), grade);
8486
}
8587
});
@@ -89,7 +91,7 @@ public static void setMaxArrival(int val) {
8991
MAX_ARRIVAL = val;
9092
}
9193

92-
public static void setStartTime(LocalTime val) {
94+
public static void setStartTime(LocalDateTime val) {
9395
START_TIME = val;
9496
}
9597

@@ -101,7 +103,11 @@ public static int getMaxArrival() {
101103
return MAX_ARRIVAL;
102104
}
103105

104-
public static LocalTime getStartTime() {
106+
public LocalDateTime getStartTime() {
107+
return START_TIME;
108+
}
109+
110+
public static LocalDateTime getStartTimeStatic(){
105111
return START_TIME;
106112
}
107113

Diff for: src/main/java/com/softeer/podoarrival/event/service/ArrivalEventService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import reactor.core.publisher.Flux;
99

1010
import java.time.Duration;
11-
import java.time.LocalTime;
11+
import java.time.LocalDateTime;
1212
import java.util.concurrent.CompletableFuture;
1313

1414
@Slf4j
@@ -37,8 +37,8 @@ public Flux<Long> streamLeftSecondsToEventTime() {
3737
Flux.just(0L), // Emit initial value immediately
3838
Flux.interval(Duration.ofSeconds(20)))
3939
.map(sequence -> {
40-
LocalTime startTime = ArrivalEventReleaseServiceJavaImpl.getStartTime();
41-
long seconds = Duration.between(LocalTime.now(), startTime).getSeconds();
40+
LocalDateTime startTime = arrivalEventReleaseServiceRedisImpl.getStartTime();
41+
long seconds = Duration.between(LocalDateTime.now(), startTime).getSeconds();
4242
return Math.max(seconds, 0);
4343
});
4444
}

Diff for: src/test/java/com/softeer/podoarrival/unit/scheduler/ArrivalEventInformationTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public void setArrivalEventCountSuccess_Data_Exists() {
4848
.isEqualTo(60);
4949
Assertions.assertThat(ArrivalEventReleaseServiceJavaImpl.getMaxArrival())
5050
.isEqualTo(60);
51-
Assertions.assertThat(ArrivalEventReleaseServiceRedisImpl.getStartTime())
51+
Assertions.assertThat(ArrivalEventReleaseServiceRedisImpl.getStartTimeStatic())
5252
.isEqualTo(LocalTime.of(15, 0));
53-
Assertions.assertThat(ArrivalEventReleaseServiceJavaImpl.getStartTime())
53+
Assertions.assertThat(ArrivalEventReleaseServiceJavaImpl.getStartTimeStatic())
5454
.isEqualTo(LocalTime.of(15, 0));
5555
}
5656

0 commit comments

Comments
 (0)