Skip to content

Commit

Permalink
refactor(coin): randomNumber 가져오는 로직을 메서드화
Browse files Browse the repository at this point in the history
  • Loading branch information
마현우 committed May 2, 2024
1 parent 2344cb7 commit 01f5442
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.project.bumawiki.domain.coin.implementation.TradeUpdater;
import com.project.bumawiki.domain.coin.implementation.TradeValidator;
import com.project.bumawiki.domain.user.domain.User;
import com.project.bumawiki.global.error.exception.BumawikiException;
import com.project.bumawiki.global.error.exception.ErrorCode;

import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -110,12 +112,7 @@ public void cancelTrade(Long tradeId, User user) {
}

public Long dailyCheck(User user) {
long min = 50000;
long max = 200000;

SecureRandom random = getRandomInstance();
long randomNumber = random.nextLong(max - min + 1) + min;
randomNumber -= randomNumber % 10000;
long randomNumber = getRandomNumber();

CoinAccount account = coinAccountReader.getByUserId(user.getId());

Expand All @@ -126,4 +123,19 @@ public Long dailyCheck(User user) {

return randomNumber;
}

private long getRandomNumber() {
long min = 50000;
long max = 200000;

SecureRandom random = getRandomInstance();

long randomNumber = random
.longs(min, max)
.findFirst()
.orElseThrow(() -> new BumawikiException(ErrorCode.INTERNAL_SERVER_ERROR));
randomNumber -= randomNumber % 10000;

return randomNumber;
}
}

0 comments on commit 01f5442

Please sign in to comment.