Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d99c3d5

Browse files
committedJun 18, 2023
refactor: LottoServiceRound 사용시 도메인 의존적인 파라미터를 사용하지 않도록 변경
1 parent c53fe45 commit d99c3d5

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed
 

‎src/main/kotlin/lotto/domain/LottoServiceRound.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import lotto.domain.Money.Companion.toMoney
55
class LottoServiceRound {
66
private val lottoRound = LottoRound(LottoRoundElements())
77

8-
fun buyLottos(payment: Money): List<Lotto> {
8+
fun buyLottos(payment: Long): List<Lotto> {
99
lottoRound.addNewLottos(payment.buyableCount())
1010
return lottoRound.getLottos()
1111
}
1212

13-
fun allPayment(): Money = (lottoRound.getLottos().size * LOTTO_BUY_PRIZE.value).toMoney()
13+
fun allPayment(): Long = (lottoRound.getLottos().size * LOTTO_BUY_PRIZE.value)
1414

1515
fun lotteryDraw(numbers: List<Int>): LottoRoundStatistics {
1616
val winningLotto = Lotto.of(numbers)
1717
return lottoRound.lotteryDraw(winningLotto)
1818
}
1919

20-
private fun Money.buyableCount(): Int = (value / LOTTO_BUY_PRIZE.value).toInt()
20+
private fun Long.buyableCount(): Int = (this / LOTTO_BUY_PRIZE.value).toInt()
2121

2222
companion object {
2323
private val LOTTO_BUY_PRIZE = 1000L.toMoney()

‎src/main/kotlin/main.kt

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import lotto.domain.LottoServiceRound
2-
import lotto.domain.Money.Companion.toMoney
32
import lotto.view.LottoInputView
43
import lotto.view.LottoOutputView
54

@@ -11,11 +10,9 @@ fun lotto() {
1110
val lottoOutputView = LottoOutputView()
1211

1312
val payment = lottoInputView.inputLottoBuy()
14-
lottoServiceRound.buyLottos(payment.toLong().toMoney()).also {
15-
lottoOutputView.currentLottos(it)
16-
}
13+
lottoServiceRound.buyLottos(payment.toLong()).also { lottoOutputView.currentLottos(it) }
1714

1815
val winningLottoNumbers = lottoInputView.inputWinningLotto()
1916
val lottoRoundStatistics = lottoServiceRound.lotteryDraw(winningLottoNumbers)
20-
lottoOutputView.result(lottoServiceRound.allPayment().value, lottoRoundStatistics)
17+
lottoOutputView.result(lottoServiceRound.allPayment(), lottoRoundStatistics)
2118
}

0 commit comments

Comments
 (0)
Please sign in to comment.