Merge pull request 'memberId가 특정 번호일 때 currency와 관계없이 모든 구매 가능한 캔이 출력되도록 수정' (#377) from test into main
Reviewed-on: #377
This commit is contained in:
@@ -14,8 +14,11 @@ import org.springframework.web.bind.annotation.RestController
|
||||
@RequestMapping("/can")
|
||||
class CanController(private val service: CanService) {
|
||||
@GetMapping
|
||||
fun getCans(): ApiResponse<List<CanResponse>> {
|
||||
return ApiResponse.ok(service.getCans())
|
||||
fun getCans(
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
): ApiResponse<List<CanResponse>> {
|
||||
val isNotSelectedCurrency = member != null && member.id == 2L
|
||||
return ApiResponse.ok(service.getCans(isNotSelectedCurrency = isNotSelectedCurrency))
|
||||
}
|
||||
|
||||
@GetMapping("/status")
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.stereotype.Repository
|
||||
interface CanRepository : JpaRepository<Can, Long>, CanQueryRepository
|
||||
|
||||
interface CanQueryRepository {
|
||||
fun findAllByStatusAndCurrency(status: CanStatus, currency: String): List<CanResponse>
|
||||
fun findAllByStatusAndCurrency(status: CanStatus, currency: String?): List<CanResponse>
|
||||
fun getCanUseStatus(member: Member, pageable: Pageable): List<UseCan>
|
||||
fun getCanChargeStatus(member: Member, pageable: Pageable, container: String): List<Charge>
|
||||
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<CanResponse> {
|
||||
override fun findAllByStatusAndCurrency(status: CanStatus, currency: String?): List<CanResponse> {
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -15,11 +15,15 @@ class CanService(
|
||||
private val repository: CanRepository,
|
||||
private val countryContext: CountryContext
|
||||
) {
|
||||
fun getCans(): List<CanResponse> {
|
||||
val currency = when (countryContext.countryCode) {
|
||||
fun getCans(isNotSelectedCurrency: Boolean): List<CanResponse> {
|
||||
val currency = if (isNotSelectedCurrency) {
|
||||
null
|
||||
} else {
|
||||
when (countryContext.countryCode) {
|
||||
"KR" -> "KRW"
|
||||
else -> "USD"
|
||||
}
|
||||
}
|
||||
return repository.findAllByStatusAndCurrency(status = CanStatus.SALE, currency = currency)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user