Skip to content

Commit

Permalink
Merge pull request #134 from mash-up-kr/junhyoung/feat-count-currents…
Browse files Browse the repository at this point in the history
…heet-totial-pick

feat: 현재 운영중인 QuestionSet에서 총 지급된 coin 반환 API
  • Loading branch information
toychip authored Sep 21, 2024
2 parents 1f13382 + 98e7a64 commit ef67561
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions _endpoint_test/coin.http
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
### 현재 유저 코인 정보 조회
GET {{host}}/coin

### 투표 종료 후 요청하는 API, 현재 운영중인 QuestionSheet 중 pick 개수로 지급된 코인 반환 API
GET {{host}}/coin/current/question-set/solved-picks
15 changes: 15 additions & 0 deletions api/src/main/kotlin/com/mashup/dojo/CoinController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ class CoinController(
.let { DojoApiResponse.success(it) }
}

@GetMapping("/current/question-set/solved-picks")
@Operation(
summary = "현재 운영중인 QuestionSheet에서 지급된 코인을 반환합니다.",
description = "현재 운영중인 QuestionSheet에서 지급된 코인 반환 API",
responses = [
ApiResponse(responseCode = "200", description = "투표 완료 보상 제공 성공")
]
)
fun getCoinBySolvedPick(): DojoApiResponse<CoinUseCase.CoinBySolvedPick> {
val memberId = MemberPrincipalContextHolder.current().id
return coinUseCase.getCoinBySolvedPickList(memberId).let {
DojoApiResponse.success(it)
}
}

@PostMapping("/admin/update")
@Operation(
summary = "관리자가 직접 특정 사용자에게 잼을 제공하는 API",
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dojo:
size: 8
rank:
size: 3
coin:
solvedPick: 20
profile:
male: ENC(y7SDgKPyWwAg4dJMql9v7uWrAdJRQoMCHyPLxvma89kwZgpCKhva2Qi9Yfn7XBEyP6Z1hPVdfAJ4cuvcjoglQ1Obp3HtOc6+4+IXG7jttKCIA+sWpf9D3FagSvybbjN7BxgXrWIkloQ=)
female: ENC(G6ycXZSiw82d4TkZ8q5TOGbV/PnPW5TMvBPx6a0hojXGIm3c3Ho/K5FqNBhuKl/m2pSIPzK5ammRqCCKpFw6+S8YvjrmWumC/ky6ciXrIKAbriS45RwKNuprrpnT+zyVcdf0M8VXBnI=)
Expand Down
25 changes: 25 additions & 0 deletions service/src/main/kotlin/com/mashup/dojo/usecase/CoinUseCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import com.mashup.dojo.domain.MemberId
import com.mashup.dojo.domain.MemberPlatform
import com.mashup.dojo.service.CoinService
import com.mashup.dojo.service.MemberService
import com.mashup.dojo.service.PickService
import com.mashup.dojo.service.QuestionService
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional

Expand All @@ -21,17 +24,25 @@ interface CoinUseCase {

data class EarnCoinByEventCommand(val currentMemberId: MemberId, val fullName: String, val platform: String?, val coinAmount: Long)

data class CoinBySolvedPick(val amount: Int)

fun getCurrentCoin(command: GetCurrentCoinCommand): Coin

fun earnCoin(command: EarnCoinCommand): CoinUseDetailId

fun earnCoinByEvent(command: EarnCoinByEventCommand): CoinUseDetailId

fun getCoinBySolvedPickList(memberId: MemberId): CoinBySolvedPick
}

@Component
class DefaultCoinUseCase(
private val coinService: CoinService,
private val membersService: MemberService,
private val questionService: QuestionService,
private val pickService: PickService,
@Value("\${dojo.coin.solvedPick}")
private val provideCoinByCompletePick: Int,
) : CoinUseCase {
override fun getCurrentCoin(command: CoinUseCase.GetCurrentCoinCommand): Coin {
return coinService.getCoin(command.memberId) ?: throw DojoException.of(DojoExceptionType.NOT_EXIST, "유저의 코인정보가 없습니다")
Expand All @@ -52,6 +63,20 @@ class DefaultCoinUseCase(
return earnCoin(CoinUseCase.EarnCoinCommand(findMember.id, command.coinAmount))
}

override fun getCoinBySolvedPickList(memberId: MemberId): CoinUseCase.CoinBySolvedPick {
val operatingQSet =
questionService.getOperatingQuestionSet()
?: throw DojoException.of(DojoExceptionType.QUESTION_SET_OPERATING_NOT_EXIST)

val solvedPickCount =
pickService.getSolvedPickList(
pickerMemberId = memberId,
questionSetId = operatingQSet.id
).size

return CoinUseCase.CoinBySolvedPick(solvedPickCount * provideCoinByCompletePick)
}

// todo 추후 Role을 넣어서 Security에서 관리하도록하면 좋을듯합니다.
private fun validAdmin(currentMemberId: MemberId) {
val currentMember =
Expand Down

0 comments on commit ef67561

Please sign in to comment.