Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 선착순 응모가 완료되면 다음날 이벤트시간으로 카운트다운 되도록 수정 #29

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,6 +36,8 @@ public CompletableFuture<CommonResponse<ArrivalApplicationResponseDto>> 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("[비동기 에러] 선착순 요청 중 서버 오류 발생");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArrivalApplicationResponseDto> applyEvent(AuthInfo authInfo);

public LocalDateTime getStartTime();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -43,7 +45,7 @@ public class ArrivalEventReleaseServiceJavaImpl implements ArrivalEventReleaseSe
public CompletableFuture<ArrivalApplicationResponseDto> 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);
Expand All @@ -69,6 +71,7 @@ public CompletableFuture<ArrivalApplicationResponseDto> 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);
}
});
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

/**
Expand All @@ -49,7 +50,7 @@ public CompletableFuture<ArrivalApplicationResponseDto> 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);
Expand Down Expand Up @@ -80,6 +81,7 @@ public CompletableFuture<ArrivalApplicationResponseDto> 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);
}
});
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,8 +37,8 @@ public Flux<Long> 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);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Loading