From 1a009ebc49adea6c32f2388a9d71bb2ad7386647 Mon Sep 17 00:00:00 2001 From: xonmin Date: Mon, 16 Sep 2024 17:38:51 +0900 Subject: [PATCH 1/2] =?UTF-8?q?add=20:=20pick=20=EC=99=84=EB=A3=8C=20?= =?UTF-8?q?=EC=8B=9C,=20=EB=B3=B4=EC=83=81=20=EC=9E=BC=20=EC=A0=9C?= =?UTF-8?q?=EA=B3=B5=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mashup/dojo/service/CoinService.kt | 20 +++++++++ .../com/mashup/dojo/usecase/PickUseCase.kt | 43 +++++++++++++------ 2 files changed, 51 insertions(+), 12 deletions(-) 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 a5cef6a..060b294 100644 --- a/service/src/main/kotlin/com/mashup/dojo/service/CoinService.kt +++ b/service/src/main/kotlin/com/mashup/dojo/service/CoinService.kt @@ -4,6 +4,8 @@ import com.mashup.dojo.CoinEntity import com.mashup.dojo.CoinRepository import com.mashup.dojo.CoinUseDetailEntity import com.mashup.dojo.CoinUseDetailRepository +import com.mashup.dojo.DojoException +import com.mashup.dojo.DojoExceptionType import com.mashup.dojo.UsageStatus import com.mashup.dojo.domain.Coin import com.mashup.dojo.domain.CoinId @@ -11,6 +13,7 @@ import com.mashup.dojo.domain.CoinUseDetail import com.mashup.dojo.domain.CoinUseDetailId import com.mashup.dojo.domain.CoinUseType import com.mashup.dojo.domain.MemberId +import jakarta.transaction.Transactional import org.springframework.stereotype.Service interface CoinService { @@ -18,6 +21,8 @@ interface CoinService { fun create(memberId: MemberId): CoinId + fun rewardCoinForCompletePick(memberId: MemberId): CoinUseDetailId + fun updateCoin( useType: CoinUseType, detail: String, @@ -45,6 +50,17 @@ class DefaultCoinService( return coin.id } + @Transactional + override fun rewardCoinForCompletePick(memberId: MemberId): CoinUseDetailId { + val coin = getCoin(memberId) ?: throw DojoException.of(DojoExceptionType.NOT_EXIST, "유저의 코인정보가 없습니다") + return updateCoin( + useType = CoinUseType.EARNED, + detail = CoinUseDetail.REASON_COMPLETE_PICK, + cost = COMPLETE_PICK_COIN_AMOUNT, + coin = coin + ) + } + override fun updateCoin( useType: CoinUseType, detail: String, @@ -63,6 +79,10 @@ class DefaultCoinService( val coinUseDetailEntity = coinUseDetailRepository.save(coinUseDetail.toEntity()) return CoinUseDetailId(coinUseDetailEntity.id) } + + companion object { + private const val COMPLETE_PICK_COIN_AMOUNT = 200 + } } 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 0754dee..ceac013 100644 --- a/service/src/main/kotlin/com/mashup/dojo/usecase/PickUseCase.kt +++ b/service/src/main/kotlin/com/mashup/dojo/usecase/PickUseCase.kt @@ -21,10 +21,14 @@ import com.mashup.dojo.service.QuestionService import com.mashup.dojo.usecase.PickUseCase.GetReceivedPickPagingCommand import com.mashup.dojo.usecase.PickUseCase.OpenPickCommand import com.mashup.dojo.usecase.PickUseCase.PickOpenInfo +import io.github.oshai.kotlinlogging.KotlinLogging +import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Component import org.springframework.transaction.annotation.Transactional import java.time.LocalDateTime +private val log = KotlinLogging.logger {} + interface PickUseCase { data class GetReceivedPickPagingCommand( val memberId: MemberId, @@ -86,6 +90,8 @@ interface PickUseCase { @Component class DefaultPickUseCase( + @Value("\${dojo.questionSet.size}") + private val questionSetSize: Int, private val pickService: PickService, private val questionService: QuestionService, private val imageService: ImageService, @@ -112,19 +118,32 @@ class DefaultPickUseCase( val questionSet = questionService.getQuestionSetById(command.questionSetId) ?: throw DojoException.of(DojoExceptionType.QUESTION_SET_NOT_EXIST) - return pickService.create( - questionId = question.id, - questionSetId = questionSet.id, - questionSheetId = command.questionSheetId, - pickerMemberId = command.pickerId, - pickedMemberId = pickedMember.id - ).apply { - notificationService.notifyPicked( - pickId = this, - target = pickedMember, - questionId = question.id - ) + val pickId = + pickService.create( + questionId = question.id, + questionSetId = questionSet.id, + questionSheetId = command.questionSheetId, + pickerMemberId = command.pickerId, + pickedMemberId = pickedMember.id + ).apply { + notificationService.notifyPicked( + pickId = this, + target = pickedMember, + questionId = question.id + ) + } + + // QSet 에 대한 모든 픽을 완료한 경우, 보상으로 코인 제공 + if (pickService.getSolvedPickList(command.pickerId, questionSet.id).size == questionSetSize) { + coinService.rewardCoinForCompletePick(command.pickerId) + .also { coinUseDetailId -> + log.info { + "reward for Complete pick. memberId: [${command.pickerId}], QSetId: [${questionSet.id}], coinUseDetailId: $coinUseDetailId" + } + } } + + return pickId } @Transactional From 7acf737123bc14504d2776d119ab8f110973b4d9 Mon Sep 17 00:00:00 2001 From: xonmin Date: Mon, 16 Sep 2024 18:41:46 +0900 Subject: [PATCH 2/2] refactor : ktlint format --- .../src/main/kotlin/com/mashup/dojo/service/CoinService.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 060b294..810328d 100644 --- a/service/src/main/kotlin/com/mashup/dojo/service/CoinService.kt +++ b/service/src/main/kotlin/com/mashup/dojo/service/CoinService.kt @@ -53,11 +53,13 @@ class DefaultCoinService( @Transactional override fun rewardCoinForCompletePick(memberId: MemberId): CoinUseDetailId { val coin = getCoin(memberId) ?: throw DojoException.of(DojoExceptionType.NOT_EXIST, "유저의 코인정보가 없습니다") + val updatedCoin = coin.earnCoin(COMPLETE_PICK_COIN_AMOUNT.toLong()) + return updateCoin( useType = CoinUseType.EARNED, detail = CoinUseDetail.REASON_COMPLETE_PICK, cost = COMPLETE_PICK_COIN_AMOUNT, - coin = coin + coin = updatedCoin ) }