Skip to content

Commit

Permalink
refactor: LottoServiceRound 사용시 도메인 의존적인 파라미터를 사용하지 않도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
qktlf789456 committed Jun 19, 2023
1 parent 2dc324a commit 7f1fde6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/main/kotlin/lotto/domain/LottoServiceRound.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import lotto.domain.Money.Companion.toMoney
class LottoServiceRound {
private val lottoRound = LottoRound(LottoRoundElements())

fun buyLottos(payment: Money): List<Lotto> {
fun buyLottos(payment: Long): List<Lotto> {
lottoRound.addNewLottos(payment.buyableCount())
return lottoRound.getLottos()
}

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

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

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

companion object {
private val LOTTO_BUY_PRIZE = 1000L.toMoney()
Expand Down
7 changes: 2 additions & 5 deletions src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import lotto.domain.LottoServiceRound
import lotto.domain.Money.Companion.toMoney
import lotto.view.LottoInputView
import lotto.view.LottoOutputView

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

val payment = lottoInputView.inputLottoBuy()
lottoServiceRound.buyLottos(payment.toLong().toMoney()).also {
lottoOutputView.currentLottos(it)
}
lottoServiceRound.buyLottos(payment.toLong()).also { lottoOutputView.currentLottos(it) }

val winningLottoNumbers = lottoInputView.inputWinningLotto()
val lottoRoundStatistics = lottoServiceRound.lotteryDraw(winningLottoNumbers)
lottoOutputView.result(lottoServiceRound.allPayment().value, lottoRoundStatistics)
lottoOutputView.result(lottoServiceRound.allPayment(), lottoRoundStatistics)
}

0 comments on commit 7f1fde6

Please sign in to comment.