Skip to content

Commit

Permalink
#33 [refactor] : 메서드 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbang105 committed Jun 17, 2024
1 parent b9c7ae4 commit dec8fe7
Showing 1 changed file with 4 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import lombok.extern.slf4j.Slf4j;
import org.dgu.backend.constant.Coin;
import org.dgu.backend.domain.Market;
import org.dgu.backend.domain.UpbitKey;
import org.dgu.backend.domain.User;
import org.dgu.backend.domain.UserCoin;
import org.dgu.backend.dto.DashBoardDto;
import org.dgu.backend.dto.UpbitDto;
import org.dgu.backend.exception.*;
import org.dgu.backend.exception.MarketErrorResult;
import org.dgu.backend.exception.MarketException;
import org.dgu.backend.repository.MarketRepository;
import org.dgu.backend.repository.UpbitKeyRepository;
import org.dgu.backend.repository.UserCoinRepository;
import org.dgu.backend.util.JwtUtil;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -29,21 +28,18 @@
@RequiredArgsConstructor
@Slf4j
public class DashBoardServiceImpl implements DashBoardService {
@Value("${upbit.url.account}")
private String UPBIT_URL_ACCOUNT;
@Value("${upbit.url.ticker}")
private String UPBIT_URL_TICKER;
private final JwtUtil jwtUtil;
private final UpbitApiClient upbitApiClient;
private final UpbitKeyRepository upbitKeyRepository;
private final UserCoinRepository userCoinRepository;
private final MarketRepository marketRepository;

// 유저 업비트 잔고를 반환하는 메서드
@Override
public DashBoardDto.UserAccountResponse getUserAccount(String authorizationHeader) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);
UpbitDto.Account[] accounts = getUpbitAccounts(user);
UpbitDto.Account[] accounts = upbitApiClient.getUpbitAccounts(user);

BigDecimal accountSum = getAccountSum(accounts);

Expand All @@ -56,7 +52,7 @@ public DashBoardDto.UserAccountResponse getUserAccount(String authorizationHeade
@Override
public List<DashBoardDto.UserCoinResponse> getUserCoins(String authorizationHeader) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);
UpbitDto.Account[] accounts = getUpbitAccounts(user);
UpbitDto.Account[] accounts = upbitApiClient.getUpbitAccounts(user);

return processUserCoins(accounts, user);
}
Expand Down Expand Up @@ -159,15 +155,4 @@ private BigDecimal getCoinPriceIncreaseRate(UserCoin userCoin, BigDecimal curPri
.divide(pastValue, 6, RoundingMode.HALF_UP)
.multiply(new BigDecimal("100"));
}

// 유저 업비트 계좌 정보를 조회하는 메서드
private UpbitDto.Account[] getUpbitAccounts(User user) {
UpbitKey upbitKey = upbitKeyRepository.findByUser(user);
if (Objects.isNull(upbitKey)) {
throw new UserException(UserErrorResult.NOT_FOUND_KEY);
}

String token = jwtUtil.generateUpbitToken(upbitKey);
return upbitApiClient.getUserAccountsAtUpbit(UPBIT_URL_ACCOUNT, token);
}
}

0 comments on commit dec8fe7

Please sign in to comment.