Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: 픽 스킵 기능 추가 #137

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions api/src/main/kotlin/com/mashup/dojo/PickController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -165,20 +166,18 @@ class PickController(
)
fun create(
@RequestBody request: CreatePickRequest,
): DojoApiResponse<PickId> {
): DojoApiResponse<CreatePickResponse> {
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")
Expand Down
10 changes: 10 additions & 0 deletions api/src/main/kotlin/com/mashup/dojo/dto/PickDto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
71 changes: 44 additions & 27 deletions service/src/main/kotlin/com/mashup/dojo/usecase/PickUseCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ interface PickUseCase {
val questionId: QuestionId,
val pickerId: MemberId,
val pickedId: MemberId,
val skip: Boolean,
)

data class OpenPickCommand(
Expand All @@ -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

Expand All @@ -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 {
Expand All @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 pickerId도 더미값으로 넣으면 어떨까요?
SKIP + pickerId 이런식으로 저장해도 좋을 것 같아요~

Copy link
Member

@xonmin xonmin Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pickerId 가 더미로 저장되면

val solvedQuestionIds =
pickService.getSolvedPickList(memberId, operatingQSet.id)
.map { it.questionId }

해당 부분에서 이미 푼 문제 조회가 어려워 필터링 부분도 변경되어야 합니다.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

더미값으로 넣는 이유가 따로 있을까요??
스킵도 하나의 pick으로 저장되고 있어 pickerId는 기존 memberId 넣어도 괜찮다고 생각했어요!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 그러네요. 다른곳에서 추가적으로 필터링을 안하기 위해 더미값 넣으면 어떨까 했었는데, 그럼 그대로 가는 게 좋을 것 같네요~

pickedMemberId = MemberId("SKIP")
)
}

// 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
Expand Down
Loading