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

[refactor] kisClient 리팩토링 #433

Merged
merged 58 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3185efe
feat: 예외 발생시 로깅
yonghwankim-dev Aug 11, 2024
6784735
feat: 예외 처리
yonghwankim-dev Aug 11, 2024
583f6a9
refatcotr: 불필요한 샘플 종목 생성 코드 제거
yonghwankim-dev Aug 11, 2024
c87c1dc
feat: AbstractContainerBaseTest 추상화
yonghwankim-dev Aug 11, 2024
2bd7d00
feat: AstractContainerBaseTest 추상 클래스로 변경
yonghwankim-dev Aug 11, 2024
b508fe3
feat: CheckedKisAccessToken 애노테이션 추가
yonghwankim-dev Aug 11, 2024
9fe6f61
test: fetchDividend 테스트 추가
yonghwankim-dev Aug 11, 2024
7f0a622
feat: 애노테이션 기반 AccesTokenExpiration aop 메서드 구현
yonghwankim-dev Aug 11, 2024
903d20d
test: fetchDividend 테스트에서 액세스 토큰 발급 케이스 테스트 추가
yonghwankim-dev Aug 11, 2024
59b4e07
test: 테스트 문제 해결
yonghwankim-dev Aug 11, 2024
e23d39e
refactor: fetchDividend 기존 aop 제거
yonghwankim-dev Aug 11, 2024
20049d1
feat: 메서드 바꿔치기
yonghwankim-dev Aug 12, 2024
e1ceeb1
feat: kisService의 public 메서드에 액세스 토큰 체크 애노테이션 설정
yonghwankim-dev Aug 12, 2024
e18de2b
test: kisAccessToken tearDown 처리
yonghwankim-dev Aug 12, 2024
5902ff5
test: zzFetchCurrentPrice 테스트 추가
yonghwankim-dev Aug 12, 2024
23f4cd2
refactor: fetchCurrentPrice 시그니처 변경
yonghwankim-dev Aug 12, 2024
e6d05f1
test: 테스트명 fetchCurrentPrice로 변경
yonghwankim-dev Aug 12, 2024
354bd12
refactor: 모의 도메인 webClient 제거
yonghwankim-dev Aug 12, 2024
812ce93
refactor: 모의 도메인 webClient 스프링 빈 제거
yonghwankim-dev Aug 12, 2024
39ea724
refactor: fetchClosingPrice 시그니처 변경
yonghwankim-dev Aug 12, 2024
5752bed
test: fetchClosingPrice 테스트 추가
yonghwankim-dev Aug 12, 2024
08f2b78
refactor: fetchDividendThisYear 메서드 시그니처 변경
yonghwankim-dev Aug 12, 2024
93c3e90
test: fetchDividendAll 테스트 추가
yonghwankim-dev Aug 12, 2024
75c6765
refactor: fetchDividendAll 메서드 Mono<List<KisDividend>> 반환하도록 변경
yonghwankim-dev Aug 12, 2024
4c25cd0
refactor: fetchIpo 메서드의 시그니처 변경
yonghwankim-dev Aug 12, 2024
5190fe1
feat: basicIso 메서드 추출
yonghwankim-dev Aug 12, 2024
c783b0a
feat: basicIso 매개변수명 변경
yonghwankim-dev Aug 12, 2024
96a4da1
feat: fetchSearchStockInfo 메서드 시그니처 변경
yonghwankim-dev Aug 12, 2024
c35ecbb
refactor: performGet 메서드 시그니처 변경
yonghwankim-dev Aug 12, 2024
e16b144
feat: KisProperties로 클래스명 변경
yonghwankim-dev Aug 12, 2024
4c368fe
feat: tokenUrl 시크릿 정보 변경
yonghwankim-dev Aug 12, 2024
31266d3
refactor: KisProperty 클래스 추가 및 appKey 프로퍼티 변경
yonghwankim-dev Aug 12, 2024
292e16b
refactor: KisAccessTokenRequest 클래스 생성
yonghwankim-dev Aug 12, 2024
ea40d7a
feat: 액세스 토큰 전달 방식 변경
yonghwankim-dev Aug 12, 2024
03e1944
feat: KisAccessTokenRequest getter, 공백생성자 제거, final 붙힘
yonghwankim-dev Aug 12, 2024
013d2e0
refactor: KisHeader enum 클래스 추가 및 헤더를 교체
yonghwankim-dev Aug 12, 2024
550bb12
feat: KisHeaderBuilder 구현
yonghwankim-dev Aug 12, 2024
c69f3f3
feat: fetchDividend header 변경
yonghwankim-dev Aug 12, 2024
cb12ddf
refactor: header 변경
yonghwankim-dev Aug 12, 2024
a0ab0d2
feat: KisTrIdProperties 클래스 추가
yonghwankim-dev Aug 12, 2024
4ec6632
refactor: 생성자 변경
yonghwankim-dev Aug 12, 2024
752424e
refactor: kisTrIdProperties 객체를 이용하여 변경
yonghwankim-dev Aug 12, 2024
3edbf18
test: kisService에서 액세스 토큰 실패 테스트 제거
yonghwankim-dev Aug 12, 2024
ec94563
feat: KisQueryParamBuilder 클래스 구현
yonghwankim-dev Aug 12, 2024
69a8258
refactor: 쿼리파라미터 enum으로 변경
yonghwankim-dev Aug 12, 2024
70ddba2
feat: kis 시크릿 정보 변경
yonghwankim-dev Aug 12, 2024
369bcea
refactor: fetchDividend 쿼리파라미터 빌더로 변경
yonghwankim-dev Aug 12, 2024
20434d2
refactor: fetchDiviend 메서드의 쿼리 파라미터 변경
yonghwankim-dev Aug 12, 2024
4d93a03
feat: kisClient의 메서드들의 쿼리 파라미터를 빌더로 변경
yonghwankim-dev Aug 12, 2024
b09834d
style: 코드 정리
yonghwankim-dev Aug 12, 2024
a98b3be
feat: KisCodeValue 인터페이스 정의 및 구현체 구현
yonghwankim-dev Aug 12, 2024
51cb4d2
rename: 패키지 이동
yonghwankim-dev Aug 12, 2024
b72cf13
feat: FidPeriodDivCode enum 클래스 구현
yonghwankim-dev Aug 12, 2024
7bcde08
feat: FidOrgAdjPrc enum 클래스 구현
yonghwankim-dev Aug 12, 2024
486ae55
feat: 배당금 종류인 GB1 enum 클래스 구현
yonghwankim-dev Aug 12, 2024
09196a3
feat: 상품유형 코드 enum 클래스 구현
yonghwankim-dev Aug 12, 2024
0d75038
feat: CustomerType enum 클래스 구현
yonghwankim-dev Aug 12, 2024
6396645
style: 코드 정리
yonghwankim-dev Aug 12, 2024
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: 1 addition & 1 deletion secret
Original file line number Diff line number Diff line change
@@ -1,71 +1,56 @@
package codesquad.fineants.domain.kis.aop;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import codesquad.fineants.domain.kis.client.KisAccessToken;
import codesquad.fineants.domain.kis.client.KisClient;
import codesquad.fineants.domain.kis.repository.KisAccessTokenRepository;
import codesquad.fineants.domain.kis.service.KisAccessTokenRedisService;
import codesquad.fineants.global.common.time.LocalDateTimeService;
import codesquad.fineants.global.errors.errorcode.KisErrorCode;
import codesquad.fineants.global.errors.exception.FineAntsException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;

@Slf4j
@RequiredArgsConstructor
@Aspect
@Component
@RequiredArgsConstructor
@Slf4j
public class AccessTokenAspect {

private final KisAccessTokenRepository manager;
private final KisClient client;
private final KisAccessTokenRedisService redisService;
private final LocalDateTimeService localDateTimeService;

@Pointcut("execution(* codesquad.fineants.domain.kis.service.KisService.refreshCurrentPrice())")
public void refreshCurrentPrice() {
}

@Pointcut("execution(* codesquad.fineants.domain.kis.service.KisService.refreshClosingPrice())")
public void refreshClosingPrice() {
}

@Pointcut("execution(* codesquad.fineants.domain.kis.service.KisService.fetchDividend())")
public void fetchDividend() {
}

@Before(value = "refreshCurrentPrice() || refreshClosingPrice() || fetchDividend()")
@Before(value = "@annotation(CheckedKisAccessToken) && args(..)")
public void checkAccessTokenExpiration() {
LocalDateTime now = LocalDateTime.now();
if (manager.isAccessTokenExpired(now)) {
Optional<KisAccessToken> optionalKisAccessToken = redisService.getAccessTokenMap();
if (optionalKisAccessToken.isPresent()) {
manager.refreshAccessToken(optionalKisAccessToken.get());
} else {
handleNewAccessToken(now);
}
LocalDateTime now = localDateTimeService.getLocalDateTimeWithNow();
if (!manager.isAccessTokenExpired(now)) {
return;
}
redisService.getAccessTokenMap()
.ifPresentOrElse(manager::refreshAccessToken, () ->
handleNewAccessToken().ifPresentOrElse(newKisAccessToken -> {
redisService.setAccessTokenMap(newKisAccessToken, now);
manager.refreshAccessToken(newKisAccessToken);
log.info("complete the newKisAccessToken");
}, () -> {
log.error("fail to newKisAccessToken");
throw new FineAntsException(KisErrorCode.ACCESS_TOKEN_ISSUE_FAIL);
}));
}

private void handleNewAccessToken(LocalDateTime now) {
CountDownLatch latch = new CountDownLatch(1);
client.fetchAccessToken()
.subscribe(accessToken -> {
redisService.setAccessTokenMap(accessToken, now);
manager.refreshAccessToken(accessToken);
log.info("새로운 액세스 토큰 갱신 완료");
}, error -> {
log.error("새로운 액세스 토큰 발급 에러", error);
latch.countDown();
}, latch::countDown);
try {
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
private Optional<KisAccessToken> handleNewAccessToken() {
return client.fetchAccessToken()
.onErrorResume(throwable -> Mono.empty())
.blockOptional(Duration.ofMinutes(10));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package codesquad.fineants.domain.kis.aop;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface CheckedKisAccessToken {
}
Loading