From e45fe1bf104b171b6ffbd6313c4ad7ebbdfc21a0 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 1 Oct 2025 22:29:39 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9D=BC=EB=B0=98=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EC=9A=A9=20=EC=BA=94=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EC=B6=94=EA=B0=80,=20GeoCountryFilter(GeoCou?= =?UTF-8?q?ntry.OTHER,=20GeoCountry.KR=20=EA=B5=AC=EB=B6=84=EC=9A=A9)=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vividnext/sodalive/can/CanController.kt | 8 +++++-- .../vividnext/sodalive/can/CanRepository.kt | 22 +++++++++++++++++++ .../co/vividnext/sodalive/can/CanService.kt | 9 ++++++-- .../vividnext/sodalive/common/GeoCountry.kt | 8 +++++++ .../sodalive/common/GeoCountryFilter.kt | 20 +++++++++++++++++ 5 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/common/GeoCountry.kt create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/common/GeoCountryFilter.kt 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 af53b78..3ec4ef4 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/CanController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/CanController.kt @@ -1,6 +1,7 @@ package kr.co.vividnext.sodalive.can import kr.co.vividnext.sodalive.common.ApiResponse +import kr.co.vividnext.sodalive.common.GeoCountry import kr.co.vividnext.sodalive.common.SodaException import kr.co.vividnext.sodalive.member.Member import org.springframework.data.domain.Pageable @@ -9,13 +10,16 @@ import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController +import javax.servlet.http.HttpServletRequest @RestController @RequestMapping("/can") class CanController(private val service: CanService) { @GetMapping - fun getCans(): ApiResponse> { - return ApiResponse.ok(service.getCans()) + fun getCans(request: HttpServletRequest): ApiResponse> { + val geoCountry = request.getAttribute("geoCountry") as? GeoCountry ?: GeoCountry.OTHER + println("geoCountry: $geoCountry") + return ApiResponse.ok(service.getCans(geoCountry)) } @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 ee17507..c7f08a8 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/CanRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/CanRepository.kt @@ -24,6 +24,7 @@ interface CanRepository : JpaRepository, CanQueryRepository interface CanQueryRepository { fun findAllByStatus(status: CanStatus): 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? @@ -50,6 +51,27 @@ class CanQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CanQue .fetch() } + override fun findAllByStatusAndCurrency(status: CanStatus, currency: String): List { + return queryFactory + .select( + QCanResponse( + can1.id, + can1.title, + can1.can, + can1.rewardCan, + can1.price, + can1.currency + ) + ) + .from(can1) + .where( + can1.status.eq(status), + can1.currency.eq(currency) + ) + .orderBy(can1.can.asc()) + .fetch() + } + override fun getCanUseStatus(member: Member, pageable: Pageable): List { return queryFactory .selectFrom(useCan) 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 555cc6e..27ef531 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/CanService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/CanService.kt @@ -3,6 +3,7 @@ package kr.co.vividnext.sodalive.can import kr.co.vividnext.sodalive.can.charge.ChargeStatus import kr.co.vividnext.sodalive.can.payment.PaymentGateway import kr.co.vividnext.sodalive.can.use.CanUsage +import kr.co.vividnext.sodalive.common.GeoCountry import kr.co.vividnext.sodalive.member.Member import org.springframework.data.domain.Pageable import org.springframework.stereotype.Service @@ -11,8 +12,12 @@ import java.time.format.DateTimeFormatter @Service class CanService(private val repository: CanRepository) { - fun getCans(): List { - return repository.findAllByStatus(status = CanStatus.SALE) + fun getCans(geoCountry: GeoCountry): List { + val currency = when (geoCountry) { + GeoCountry.KR -> "KRW" + else -> "USD" + } + return repository.findAllByStatusAndCurrency(status = CanStatus.SALE, currency = currency) } fun getCanStatus(member: Member, container: String): GetCanStatusResponse { diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/common/GeoCountry.kt b/src/main/kotlin/kr/co/vividnext/sodalive/common/GeoCountry.kt new file mode 100644 index 0000000..be44f32 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/common/GeoCountry.kt @@ -0,0 +1,8 @@ +package kr.co.vividnext.sodalive.common + +const val WAF_GEO_HEADER = "x-amzn-waf-geo-country" + +enum class GeoCountry { KR, OTHER } + +fun parseGeo(headerValue: String?): GeoCountry = + if (headerValue?.trim()?.uppercase() == "KR") GeoCountry.KR else GeoCountry.OTHER diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/common/GeoCountryFilter.kt b/src/main/kotlin/kr/co/vividnext/sodalive/common/GeoCountryFilter.kt new file mode 100644 index 0000000..1981f60 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/common/GeoCountryFilter.kt @@ -0,0 +1,20 @@ +package kr.co.vividnext.sodalive.common + +import org.springframework.stereotype.Component +import org.springframework.web.filter.OncePerRequestFilter +import javax.servlet.FilterChain +import javax.servlet.http.HttpServletRequest +import javax.servlet.http.HttpServletResponse + +@Component +class GeoCountryFilter : OncePerRequestFilter() { + override fun doFilterInternal( + request: HttpServletRequest, + response: HttpServletResponse, + filterChain: FilterChain + ) { + val country = parseGeo(request.getHeader(WAF_GEO_HEADER)) + request.setAttribute("geoCountry", country) + filterChain.doFilter(request, response) + } +}