From 7900abe74c7060d5a14ecf82464579c961fe2ee3 Mon Sep 17 00:00:00 2001 From: wonlog-g Date: Sun, 18 Aug 2024 23:12:14 +0900 Subject: [PATCH] =?UTF-8?q?add:=20=ED=94=BD=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=98=A4=ED=94=88=ED=95=A0=20=EB=95=8C=20=EC=BD=94=EC=9D=B8=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/mashup/dojo/domain/Coin.kt | 1 + .../com/mashup/dojo/service/CoinService.kt | 25 +++++++++++++++++++ .../com/mashup/dojo/usecase/PickUseCase.kt | 11 ++++++++ 3 files changed, 37 insertions(+) diff --git a/service/src/main/kotlin/com/mashup/dojo/domain/Coin.kt b/service/src/main/kotlin/com/mashup/dojo/domain/Coin.kt index 3bbb87b4..38962e05 100644 --- a/service/src/main/kotlin/com/mashup/dojo/domain/Coin.kt +++ b/service/src/main/kotlin/com/mashup/dojo/domain/Coin.kt @@ -48,6 +48,7 @@ data class CoinUseDetail( ) { companion object { const val REASON_PROVIDE_DEFAULT = "provide by default" + const val REASON_USED_FOR_OPEN_PICK = "used for open pick" fun createEarnedCoinUseDetail( coinId: CoinId, diff --git a/service/src/main/kotlin/com/mashup/dojo/service/CoinService.kt b/service/src/main/kotlin/com/mashup/dojo/service/CoinService.kt index 8c0e00de..c4b35fff 100644 --- a/service/src/main/kotlin/com/mashup/dojo/service/CoinService.kt +++ b/service/src/main/kotlin/com/mashup/dojo/service/CoinService.kt @@ -16,6 +16,13 @@ interface CoinService { fun getCoin(memberId: MemberId): Coin? fun create(memberId: MemberId): CoinId + + fun updateCoin( + useType: CoinUseType, + detail: String, + cost: Int, + coin: Coin, + ) } @Service @@ -36,6 +43,24 @@ class DefaultCoinService( return coin.id } + + override fun updateCoin( + useType: CoinUseType, + detail: String, + cost: Int, + coin: Coin, + ) { + coinRepository.save(coin.toEntity()) + + val coinUseDetail = + if (CoinUseType.USED == useType) { + CoinUseDetail.createUsedCoinUseDetail(coin.id, cost.toLong(), detail) + } else { + CoinUseDetail.createEarnedCoinUseDetail(coin.id, cost.toLong(), detail) + } + + coinUseDetailRepository.save(coinUseDetail.toEntity()) + } } private fun CoinEntity.toCoin(): Coin { diff --git a/service/src/main/kotlin/com/mashup/dojo/usecase/PickUseCase.kt b/service/src/main/kotlin/com/mashup/dojo/usecase/PickUseCase.kt index c082bff5..53696881 100644 --- a/service/src/main/kotlin/com/mashup/dojo/usecase/PickUseCase.kt +++ b/service/src/main/kotlin/com/mashup/dojo/usecase/PickUseCase.kt @@ -3,6 +3,8 @@ package com.mashup.dojo.usecase import com.mashup.dojo.DojoException import com.mashup.dojo.DojoExceptionType import com.mashup.dojo.Status +import com.mashup.dojo.domain.CoinUseDetail +import com.mashup.dojo.domain.CoinUseType import com.mashup.dojo.domain.MemberId import com.mashup.dojo.domain.PickId import com.mashup.dojo.domain.PickOpenItem @@ -10,6 +12,7 @@ import com.mashup.dojo.domain.PickSort import com.mashup.dojo.domain.QuestionId import com.mashup.dojo.domain.QuestionSetId import com.mashup.dojo.domain.QuestionSheetId +import com.mashup.dojo.service.CoinService import com.mashup.dojo.service.ImageService import com.mashup.dojo.service.MemberService import com.mashup.dojo.service.NotificationService @@ -19,6 +22,7 @@ import com.mashup.dojo.usecase.PickUseCase.GetReceivedPickPagingCommand import com.mashup.dojo.usecase.PickUseCase.OpenPickCommand import com.mashup.dojo.usecase.PickUseCase.PickOpenInfo import org.springframework.stereotype.Component +import org.springframework.transaction.annotation.Transactional import java.time.LocalDateTime interface PickUseCase { @@ -86,6 +90,7 @@ class DefaultPickUseCase( private val imageService: ImageService, private val memberService: MemberService, private val notificationService: NotificationService, + private val coinService: CoinService, ) : PickUseCase { override fun getReceivedPickList(command: GetReceivedPickPagingCommand): PickService.GetPickPaging { return pickService.getReceivedPickPaging( @@ -121,7 +126,13 @@ class DefaultPickUseCase( } } + @Transactional override fun openPick(openPickCommand: OpenPickCommand): PickOpenInfo { + val coin = coinService.getCoin(openPickCommand.pickedId) ?: throw DojoException.of(DojoExceptionType.NOT_EXIST, "유저의 코인정보가 없습니다") + val updatedCoin = coin.useCoin(openPickCommand.pickOpenItem.cost.toLong()) + + coinService.updateCoin(CoinUseType.USED, CoinUseDetail.REASON_USED_FOR_OPEN_PICK, openPickCommand.pickOpenItem.cost, updatedCoin) + return pickService.openPick( openPickCommand.pickId, openPickCommand.pickedId,