국가 컨텍스트로 캔 조회 #375
@@ -1,7 +1,6 @@
|
||||
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
|
||||
@@ -10,15 +9,13 @@ 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(request: HttpServletRequest): ApiResponse<List<CanResponse>> {
|
||||
val geoCountry = request.getAttribute("geoCountry") as? GeoCountry ?: GeoCountry.OTHER
|
||||
return ApiResponse.ok(service.getCans(geoCountry))
|
||||
fun getCans(): ApiResponse<List<CanResponse>> {
|
||||
return ApiResponse.ok(service.getCans())
|
||||
}
|
||||
|
||||
@GetMapping("/status")
|
||||
|
||||
@@ -3,7 +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.common.CountryContext
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import org.springframework.data.domain.Pageable
|
||||
import org.springframework.stereotype.Service
|
||||
@@ -11,10 +11,13 @@ import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
@Service
|
||||
class CanService(private val repository: CanRepository) {
|
||||
fun getCans(geoCountry: GeoCountry): List<CanResponse> {
|
||||
val currency = when (geoCountry) {
|
||||
GeoCountry.KR -> "KRW"
|
||||
class CanService(
|
||||
private val repository: CanRepository,
|
||||
private val countryContext: CountryContext
|
||||
) {
|
||||
fun getCans(): List<CanResponse> {
|
||||
val currency = when (countryContext.countryCode) {
|
||||
"KR" -> "KRW"
|
||||
else -> "USD"
|
||||
}
|
||||
return repository.findAllByStatusAndCurrency(status = CanStatus.SALE, currency = currency)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
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
|
||||
@@ -1,20 +0,0 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,10 @@ data class Member(
|
||||
|
||||
var isActive: Boolean = true,
|
||||
|
||||
var container: String = "web"
|
||||
var container: String = "web",
|
||||
|
||||
// ISO 3166-1 alpha-2 국가 코드
|
||||
var countryCode: String? = null
|
||||
) : BaseEntity() {
|
||||
@OneToMany(mappedBy = "member", cascade = [CascadeType.ALL])
|
||||
val stipulationAgrees: MutableList<StipulationAgree> = mutableListOf()
|
||||
|
||||
@@ -7,6 +7,7 @@ import kr.co.vividnext.sodalive.can.charge.ChargeRepository
|
||||
import kr.co.vividnext.sodalive.can.payment.CanPaymentService
|
||||
import kr.co.vividnext.sodalive.can.use.CanUsage
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.common.CountryContext
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import kr.co.vividnext.sodalive.content.order.OrderService
|
||||
import kr.co.vividnext.sodalive.email.SendEmailService
|
||||
@@ -99,6 +100,7 @@ class MemberService(
|
||||
|
||||
private val messageSource: SodaMessageSource,
|
||||
private val langContext: LangContext,
|
||||
private val countryContext: CountryContext,
|
||||
|
||||
private val objectMapper: ObjectMapper,
|
||||
|
||||
@@ -133,7 +135,8 @@ class MemberService(
|
||||
nickname = nickname,
|
||||
profileImage = "profile/default-profile.png",
|
||||
gender = Gender.NONE,
|
||||
container = request.container
|
||||
container = request.container,
|
||||
countryCode = countryContext.countryCode
|
||||
)
|
||||
|
||||
if (!request.marketingPid.isNullOrBlank()) {
|
||||
@@ -390,7 +393,8 @@ class MemberService(
|
||||
password = passwordEncoder.encode(request.password),
|
||||
nickname = request.nickname,
|
||||
gender = request.gender,
|
||||
container = request.container
|
||||
container = request.container,
|
||||
countryCode = countryContext.countryCode
|
||||
)
|
||||
|
||||
if (!request.marketingPid.isNullOrBlank()) {
|
||||
@@ -848,7 +852,8 @@ class MemberService(
|
||||
profileImage = "profile/default-profile.png",
|
||||
gender = Gender.NONE,
|
||||
provider = MemberProvider.GOOGLE,
|
||||
container = container
|
||||
container = container,
|
||||
countryCode = countryContext.countryCode
|
||||
)
|
||||
|
||||
if (!marketingPid.isNullOrBlank()) {
|
||||
@@ -904,7 +909,8 @@ class MemberService(
|
||||
profileImage = "profile/default-profile.png",
|
||||
gender = Gender.NONE,
|
||||
provider = MemberProvider.KAKAO,
|
||||
container = container
|
||||
container = container,
|
||||
countryCode = countryContext.countryCode
|
||||
)
|
||||
|
||||
if (!marketingPid.isNullOrBlank()) {
|
||||
|
||||
Reference in New Issue
Block a user