From c38aa25dedd39b12d0fe24810b8ed71b660f3720 Mon Sep 17 00:00:00 2001 From: wonlog-g Date: Sat, 21 Sep 2024 20:32:32 +0900 Subject: [PATCH 1/2] =?UTF-8?q?add:=20=ED=94=BD=20=EC=8A=A4=ED=82=B5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=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/PickController.kt | 23 +++--- .../kotlin/com/mashup/dojo/dto/PickDto.kt | 10 +++ .../com/mashup/dojo/usecase/PickUseCase.kt | 75 ++++++++++++------- 3 files changed, 69 insertions(+), 39 deletions(-) diff --git a/api/src/main/kotlin/com/mashup/dojo/PickController.kt b/api/src/main/kotlin/com/mashup/dojo/PickController.kt index 35a2f26..9dc8ba1 100644 --- a/api/src/main/kotlin/com/mashup/dojo/PickController.kt +++ b/api/src/main/kotlin/com/mashup/dojo/PickController.kt @@ -7,6 +7,7 @@ import com.mashup.dojo.domain.PickOpenItem import com.mashup.dojo.domain.PickSort import com.mashup.dojo.domain.QuestionId import com.mashup.dojo.dto.CreatePickRequest +import com.mashup.dojo.dto.CreatePickResponse import com.mashup.dojo.dto.PickDetailPaging import com.mashup.dojo.dto.PickOpenItemDto import com.mashup.dojo.dto.PickOpenRequest @@ -165,20 +166,18 @@ class PickController( ) fun create( @RequestBody request: CreatePickRequest, - ): DojoApiResponse { + ): DojoApiResponse { val currentMemberId = MemberPrincipalContextHolder.current().id - val pickId = - pickUseCase.createPick( - PickUseCase.CreatePickCommand( - questionSheetId = request.questionSheetId, - questionSetId = request.questionSetId, - questionId = request.questionId, - pickerId = currentMemberId, - pickedId = request.pickedId - ) + return pickUseCase.createPick( + PickUseCase.CreatePickCommand( + questionSheetId = request.questionSheetId, + questionSetId = request.questionSetId, + questionId = request.questionId, + pickerId = currentMemberId, + pickedId = request.pickedId, + skip = request.skip ) - - return DojoApiResponse.success(pickId) + ).let { DojoApiResponse.success(CreatePickResponse(it.pickId, it.coin)) } } @GetMapping("/next-pick-time") diff --git a/api/src/main/kotlin/com/mashup/dojo/dto/PickDto.kt b/api/src/main/kotlin/com/mashup/dojo/dto/PickDto.kt index 5b5aafc..6dc56ad 100644 --- a/api/src/main/kotlin/com/mashup/dojo/dto/PickDto.kt +++ b/api/src/main/kotlin/com/mashup/dojo/dto/PickDto.kt @@ -24,6 +24,16 @@ data class CreatePickRequest( val questionId: QuestionId, @Schema(description = "후보자 중 선택한 대상 멤버 id") val pickedId: MemberId, + @Schema(description = "질문 스킵 여부") + val skip: Boolean, +) + +@Schema(description = "Pick 생성 응답") +data class CreatePickResponse( + @Schema(description = "픽 id") + val pickId: PickId, + @Schema(description = "획득한 코인") + val coin: Int, ) data class ReceivedPickPagingGetResponse( 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 ceac013..8fdf461 100644 --- a/service/src/main/kotlin/com/mashup/dojo/usecase/PickUseCase.kt +++ b/service/src/main/kotlin/com/mashup/dojo/usecase/PickUseCase.kt @@ -62,6 +62,7 @@ interface PickUseCase { val questionId: QuestionId, val pickerId: MemberId, val pickedId: MemberId, + val skip: Boolean, ) data class OpenPickCommand( @@ -77,9 +78,14 @@ interface PickUseCase { val pickOpenImageUrl: String, ) + data class CreatePickInfo( + val pickId: PickId, + val coin: Int, + ) + fun getReceivedPickList(command: GetReceivedPickPagingCommand): PickService.GetPickPaging - fun createPick(command: CreatePickCommand): PickId + fun createPick(command: CreatePickCommand): CreatePickInfo fun getNextPickTime(): LocalDateTime @@ -97,6 +103,9 @@ class DefaultPickUseCase( private val imageService: ImageService, private val memberService: MemberService, private val notificationService: NotificationService, + @Value("\${dojo.coin.solvedPick}") + private val provideCoinByCompletePick: Int, + private val coinUseCase: CoinUseCase, private val coinService: CoinService, ) : PickUseCase { override fun getReceivedPickList(command: GetReceivedPickPagingCommand): PickService.GetPickPaging { @@ -108,42 +117,50 @@ class DefaultPickUseCase( ) } - override fun createPick(command: PickUseCase.CreatePickCommand): PickId { + override fun createPick(command: PickUseCase.CreatePickCommand): PickUseCase.CreatePickInfo { val question = questionService.getQuestionById(command.questionId) ?: throw DojoException.of(DojoExceptionType.NOT_EXIST, "NOT EXIST QUESTION ID ${command.questionId}") - val pickedMember = - memberService.findMemberById(command.pickedId) - ?: throw DojoException.of(DojoExceptionType.NOT_EXIST, "NOT EXIST PICKED MEMBER ID ${command.pickedId}") val questionSet = questionService.getQuestionSetById(command.questionSetId) ?: throw DojoException.of(DojoExceptionType.QUESTION_SET_NOT_EXIST) - 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 + val createPickInfo: PickUseCase.CreatePickInfo + + if (command.skip) { + val pickId = + pickService.create( + questionId = question.id, + questionSetId = questionSet.id, + questionSheetId = command.questionSheetId, + pickerMemberId = command.pickerId, + pickedMemberId = MemberId(SKIP_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" - } + createPickInfo = PickUseCase.CreatePickInfo(pickId, 0) + } else { + val pickedMember = + memberService.findMemberById(command.pickedId) + ?: throw DojoException.of(DojoExceptionType.NOT_EXIST, "NOT EXIST PICKED MEMBER ID ${command.pickedId}") + + 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 + ) } + + coinUseCase.earnCoin(CoinUseCase.EarnCoinCommand(command.pickerId, provideCoinByCompletePick.toLong())) + createPickInfo = PickUseCase.CreatePickInfo(pickId, provideCoinByCompletePick) } - return pickId + return createPickInfo } @Transactional @@ -193,4 +210,8 @@ class DefaultPickUseCase( return nextOperatingQuestionSet.publishedAt } + + companion object { + const val SKIP_ID = "SKIP" + } } From 87ec763d8bcb37868e251ce0e2ce40adfc27578d Mon Sep 17 00:00:00 2001 From: wonlog-g Date: Sat, 21 Sep 2024 20:43:03 +0900 Subject: [PATCH 2/2] =?UTF-8?q?mod:=20=EC=83=9D=EC=84=B1=ED=95=9C=20?= =?UTF-8?q?=ED=94=BD=20=EA=B0=9C=EC=88=98=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C?= =?UTF-8?q?=20=EC=8A=A4=ED=82=B5=ED=95=9C=20=ED=94=BD=20=ED=95=84=ED=84=B0?= =?UTF-8?q?=EB=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/com/mashup/dojo/usecase/CoinUseCase.kt | 2 +- .../src/main/kotlin/com/mashup/dojo/usecase/PickUseCase.kt | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/service/src/main/kotlin/com/mashup/dojo/usecase/CoinUseCase.kt b/service/src/main/kotlin/com/mashup/dojo/usecase/CoinUseCase.kt index 5f9be33..3d1b41e 100644 --- a/service/src/main/kotlin/com/mashup/dojo/usecase/CoinUseCase.kt +++ b/service/src/main/kotlin/com/mashup/dojo/usecase/CoinUseCase.kt @@ -72,7 +72,7 @@ class DefaultCoinUseCase( pickService.getSolvedPickList( pickerMemberId = memberId, questionSetId = operatingQSet.id - ).size + ).filter { pick -> pick.pickedId.value != "SKIP" }.size return CoinUseCase.CoinBySolvedPick(solvedPickCount * provideCoinByCompletePick) } 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 8fdf461..0be38d7 100644 --- a/service/src/main/kotlin/com/mashup/dojo/usecase/PickUseCase.kt +++ b/service/src/main/kotlin/com/mashup/dojo/usecase/PickUseCase.kt @@ -133,7 +133,7 @@ class DefaultPickUseCase( questionSetId = questionSet.id, questionSheetId = command.questionSheetId, pickerMemberId = command.pickerId, - pickedMemberId = MemberId(SKIP_ID) + pickedMemberId = MemberId("SKIP") ) createPickInfo = PickUseCase.CreatePickInfo(pickId, 0) } else { @@ -210,8 +210,4 @@ class DefaultPickUseCase( return nextOperatingQuestionSet.publishedAt } - - companion object { - const val SKIP_ID = "SKIP" - } }