diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/can/CanController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/can/CanController.kt index f97698c2..662dbe8f 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/CanController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/CanController.kt @@ -14,8 +14,11 @@ import org.springframework.web.bind.annotation.RestController @RequestMapping("/can") class CanController(private val service: CanService) { @GetMapping - fun getCans(): ApiResponse> { - return ApiResponse.ok(service.getCans()) + fun getCans( + @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? + ): ApiResponse> { + val isNotSelectedCurrency = member != null && member.id == 2L + return ApiResponse.ok(service.getCans(isNotSelectedCurrency = isNotSelectedCurrency)) } @GetMapping("/status") diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/can/CanRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/can/CanRepository.kt index fcc3f2f7..0019c22e 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/CanRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/CanRepository.kt @@ -23,7 +23,7 @@ import org.springframework.stereotype.Repository interface CanRepository : JpaRepository, CanQueryRepository interface CanQueryRepository { - fun findAllByStatusAndCurrency(status: CanStatus, currency: String): List + fun findAllByStatusAndCurrency(status: CanStatus, currency: String?): List fun getCanUseStatus(member: Member, pageable: Pageable): List fun getCanChargeStatus(member: Member, pageable: Pageable, container: String): List fun isExistPaidLiveRoom(memberId: Long, roomId: Long): UseCan? @@ -32,7 +32,13 @@ interface CanQueryRepository { @Repository class CanQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CanQueryRepository { - override fun findAllByStatusAndCurrency(status: CanStatus, currency: String): List { + override fun findAllByStatusAndCurrency(status: CanStatus, currency: String?): List { + var where = can1.status.eq(status) + + if (currency != null) { + where = where.and(can1.currency.eq(currency)) + } + return queryFactory .select( QCanResponse( @@ -46,10 +52,7 @@ class CanQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CanQue ) ) .from(can1) - .where( - can1.status.eq(status), - can1.currency.eq(currency) - ) + .where(where) .orderBy(can1.can.asc()) .fetch() } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/can/CanService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/can/CanService.kt index 24994f33..bd433c6c 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/CanService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/CanService.kt @@ -15,10 +15,14 @@ class CanService( private val repository: CanRepository, private val countryContext: CountryContext ) { - fun getCans(): List { - val currency = when (countryContext.countryCode) { - "KR" -> "KRW" - else -> "USD" + fun getCans(isNotSelectedCurrency: Boolean): List { + val currency = if (isNotSelectedCurrency) { + null + } else { + when (countryContext.countryCode) { + "KR" -> "KRW" + else -> "USD" + } } return repository.findAllByStatusAndCurrency(status = CanStatus.SALE, currency = currency) }