Merge pull request 'test' (#31) from test into main

Reviewed-on: #31
This commit is contained in:
klaus 2023-09-19 06:32:22 +00:00
commit a3d93d4b08
17 changed files with 197 additions and 13 deletions

View File

@ -293,9 +293,9 @@ class AdminLiveService(
charge.useCan = useCan charge.useCan = useCan
when (it.paymentGateway) { when (it.paymentGateway) {
PaymentGateway.PG -> booker.pgRewardCan += charge.rewardCan
PaymentGateway.GOOGLE_IAP -> booker.googleRewardCan += charge.rewardCan PaymentGateway.GOOGLE_IAP -> booker.googleRewardCan += charge.rewardCan
PaymentGateway.APPLE_IAP -> booker.appleRewardCan += charge.rewardCan PaymentGateway.APPLE_IAP -> booker.appleRewardCan += charge.rewardCan
else -> booker.pgRewardCan += charge.rewardCan
} }
charge.member = booker charge.member = booker

View File

@ -21,7 +21,7 @@ data class Charge(
@Enumerated(value = EnumType.STRING) @Enumerated(value = EnumType.STRING)
var status: ChargeStatus = ChargeStatus.CHARGE var status: ChargeStatus = ChargeStatus.CHARGE
) : BaseEntity() { ) : BaseEntity() {
@OneToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "can_id", nullable = true) @JoinColumn(name = "can_id", nullable = true)
var can: Can? = null var can: Can? = null

View File

@ -4,5 +4,8 @@ enum class ChargeStatus {
CHARGE, REFUND_CHARGE, EVENT, CANCEL, CHARGE, REFUND_CHARGE, EVENT, CANCEL,
// 관리자 지급 // 관리자 지급
ADMIN ADMIN,
// 광고
ADS
} }

View File

@ -122,9 +122,9 @@ class ChargeEventService(
chargeRepository.save(eventCharge) chargeRepository.save(eventCharge)
when (paymentGateway) { when (paymentGateway) {
PaymentGateway.PG -> member.charge(0, additionalCan, "pg")
PaymentGateway.GOOGLE_IAP -> member.charge(0, additionalCan, "aos") PaymentGateway.GOOGLE_IAP -> member.charge(0, additionalCan, "aos")
PaymentGateway.APPLE_IAP -> member.charge(0, additionalCan, "ios") PaymentGateway.APPLE_IAP -> member.charge(0, additionalCan, "ios")
else -> member.charge(0, additionalCan, "pg")
} }
} }
} }

View File

@ -0,0 +1,23 @@
package kr.co.vividnext.sodalive.can.charge.free
import kr.co.vividnext.sodalive.common.BaseEntity
import kr.co.vividnext.sodalive.member.Member
import javax.persistence.Entity
import javax.persistence.FetchType
import javax.persistence.JoinColumn
import javax.persistence.ManyToOne
@Entity
data class AdsCharge(
val transactionKey: String,
val adKey: String,
val adName: String,
val adProfit: Int,
val adCurrency: String,
val point: Int,
val deviceIfa: String
) : BaseEntity() {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
var member: Member? = null
}

View File

@ -0,0 +1,35 @@
package kr.co.vividnext.sodalive.can.charge.free
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
@RestController
@RequestMapping("/charge/ads")
class AdsChargeController(private val service: AdsChargeService) {
@GetMapping
fun adsCharge(
@RequestParam("transaction_key") transactionKey: String,
@RequestParam("placement_uid") placementUid: String,
@RequestParam("ad_key") adKey: String,
@RequestParam("ad_name") adName: String,
@RequestParam("ad_profit") adProfit: String,
@RequestParam("ad_currency") adCurrency: String,
@RequestParam("point") point: String,
@RequestParam("device_ifa") deviceIfa: String,
@RequestParam("picker_uid") memberId: String
) {
service.adsCharge(
transactionKey,
placementUid,
adKey,
adName,
adProfit,
adCurrency,
point,
deviceIfa,
memberId
)
}
}

View File

@ -0,0 +1,7 @@
package kr.co.vividnext.sodalive.can.charge.free
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
@Repository
interface AdsChargeRepository : JpaRepository<AdsCharge, Long>

View File

@ -0,0 +1,85 @@
package kr.co.vividnext.sodalive.can.charge.free
import kr.co.vividnext.sodalive.can.charge.Charge
import kr.co.vividnext.sodalive.can.charge.ChargeRepository
import kr.co.vividnext.sodalive.can.charge.ChargeStatus
import kr.co.vividnext.sodalive.can.payment.Payment
import kr.co.vividnext.sodalive.can.payment.PaymentGateway
import kr.co.vividnext.sodalive.can.payment.PaymentStatus
import kr.co.vividnext.sodalive.common.AdsChargeException
import kr.co.vividnext.sodalive.fcm.FcmEvent
import kr.co.vividnext.sodalive.fcm.FcmEventType
import kr.co.vividnext.sodalive.member.MemberRepository
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.ApplicationEventPublisher
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
@Service
class AdsChargeService(
private val repository: AdsChargeRepository,
private val memberRepository: MemberRepository,
private val chargeRepository: ChargeRepository,
private val applicationEventPublisher: ApplicationEventPublisher,
@Value("\${point-click.placement-uid}")
private val placementUid: String
) {
@Transactional
fun adsCharge(
transactionKey: String,
placementUid: String,
adKey: String,
adName: String,
adProfit: String,
adCurrency: String,
point: String,
deviceIfa: String,
memberId: String
) {
if (placementUid != this.placementUid) {
throw AdsChargeException("잘못된 요청입니다.")
}
val member = memberRepository.findByIdOrNull(id = memberId.toLong())
?: throw AdsChargeException("잘못된 요청입니다.")
val adsCharge = AdsCharge(
transactionKey = transactionKey,
adKey = adKey,
adName = adName,
adProfit = adProfit.toInt(),
adCurrency = adCurrency,
point = point.toInt(),
deviceIfa = deviceIfa
)
adsCharge.member = member
repository.save(adsCharge)
val charge = Charge(0, rewardCan = point.toInt(), status = ChargeStatus.ADS)
charge.title = "${point.toInt()}"
charge.member = member
val payment = Payment(
status = PaymentStatus.COMPLETE,
paymentGateway = PaymentGateway.POINT_CLICK_AD
)
payment.method = "제휴보상"
charge.payment = payment
chargeRepository.save(charge)
member.charge(0, point.toInt(), "ads")
applicationEventPublisher.publishEvent(
FcmEvent(
type = FcmEventType.INDIVIDUAL,
title = "제휴보상",
message = "${point.toInt()} 캔이 지급되었습니다.",
recipients = listOf(member.id!!),
isAuth = false
)
)
}
}

View File

@ -162,9 +162,9 @@ class CanPaymentService(
charge.rewardCan -= remainingNeedCan charge.rewardCan -= remainingNeedCan
when (charge.payment!!.paymentGateway) { when (charge.payment!!.paymentGateway) {
PaymentGateway.PG -> member.pgRewardCan -= remainingNeedCan
PaymentGateway.APPLE_IAP -> member.appleRewardCan -= remainingNeedCan PaymentGateway.APPLE_IAP -> member.appleRewardCan -= remainingNeedCan
PaymentGateway.GOOGLE_IAP -> member.googleRewardCan -= remainingNeedCan PaymentGateway.GOOGLE_IAP -> member.googleRewardCan -= remainingNeedCan
else -> member.pgRewardCan -= remainingNeedCan
} }
total += remainingNeedCan total += remainingNeedCan
@ -185,9 +185,9 @@ class CanPaymentService(
) )
when (charge.payment!!.paymentGateway) { when (charge.payment!!.paymentGateway) {
PaymentGateway.PG -> member.pgRewardCan -= charge.rewardCan
PaymentGateway.APPLE_IAP -> member.appleRewardCan -= charge.rewardCan PaymentGateway.APPLE_IAP -> member.appleRewardCan -= charge.rewardCan
PaymentGateway.GOOGLE_IAP -> member.googleRewardCan -= charge.rewardCan PaymentGateway.GOOGLE_IAP -> member.googleRewardCan -= charge.rewardCan
else -> member.pgRewardCan -= charge.rewardCan
} }
charge.rewardCan = 0 charge.rewardCan = 0
@ -220,9 +220,9 @@ class CanPaymentService(
charge.chargeCan -= remainingNeedCan charge.chargeCan -= remainingNeedCan
when (charge.payment!!.paymentGateway) { when (charge.payment!!.paymentGateway) {
PaymentGateway.PG -> member.pgChargeCan -= remainingNeedCan
PaymentGateway.APPLE_IAP -> member.appleChargeCan -= remainingNeedCan PaymentGateway.APPLE_IAP -> member.appleChargeCan -= remainingNeedCan
PaymentGateway.GOOGLE_IAP -> member.googleChargeCan -= remainingNeedCan PaymentGateway.GOOGLE_IAP -> member.googleChargeCan -= remainingNeedCan
else -> member.pgChargeCan -= remainingNeedCan
} }
total += remainingNeedCan total += remainingNeedCan
@ -243,9 +243,9 @@ class CanPaymentService(
) )
when (charge.payment!!.paymentGateway) { when (charge.payment!!.paymentGateway) {
PaymentGateway.PG -> member.pgChargeCan -= charge.chargeCan
PaymentGateway.APPLE_IAP -> member.appleChargeCan -= charge.chargeCan PaymentGateway.APPLE_IAP -> member.appleChargeCan -= charge.chargeCan
PaymentGateway.GOOGLE_IAP -> member.pgChargeCan -= charge.chargeCan PaymentGateway.GOOGLE_IAP -> member.pgChargeCan -= charge.chargeCan
else -> member.pgChargeCan -= charge.chargeCan
} }
charge.chargeCan = 0 charge.chargeCan = 0
@ -280,9 +280,9 @@ class CanPaymentService(
charge.useCan = useCan charge.useCan = useCan
when (it.paymentGateway) { when (it.paymentGateway) {
PaymentGateway.PG -> member.pgRewardCan += charge.rewardCan
PaymentGateway.GOOGLE_IAP -> member.googleRewardCan += charge.rewardCan PaymentGateway.GOOGLE_IAP -> member.googleRewardCan += charge.rewardCan
PaymentGateway.APPLE_IAP -> member.appleRewardCan += charge.rewardCan PaymentGateway.APPLE_IAP -> member.appleRewardCan += charge.rewardCan
else -> member.pgRewardCan += charge.rewardCan
} }
charge.member = member charge.member = member

View File

@ -1,5 +1,5 @@
package kr.co.vividnext.sodalive.can.payment package kr.co.vividnext.sodalive.can.payment
enum class PaymentGateway { enum class PaymentGateway {
PG, GOOGLE_IAP, APPLE_IAP PG, GOOGLE_IAP, APPLE_IAP, POINT_CLICK_AD
} }

View File

@ -1,3 +1,5 @@
package kr.co.vividnext.sodalive.common package kr.co.vividnext.sodalive.common
class SodaException(message: String, val errorProperty: String? = null) : RuntimeException(message) class SodaException(message: String, val errorProperty: String? = null) : RuntimeException(message)
class AdsChargeException(message: String) : RuntimeException(message)

View File

@ -2,10 +2,12 @@ package kr.co.vividnext.sodalive.common
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import org.springframework.dao.DataIntegrityViolationException import org.springframework.dao.DataIntegrityViolationException
import org.springframework.http.HttpStatus
import org.springframework.security.access.AccessDeniedException import org.springframework.security.access.AccessDeniedException
import org.springframework.security.authentication.BadCredentialsException import org.springframework.security.authentication.BadCredentialsException
import org.springframework.security.authentication.InternalAuthenticationServiceException import org.springframework.security.authentication.InternalAuthenticationServiceException
import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestControllerAdvice import org.springframework.web.bind.annotation.RestControllerAdvice
import org.springframework.web.multipart.MaxUploadSizeExceededException import org.springframework.web.multipart.MaxUploadSizeExceededException
@ -52,6 +54,13 @@ class SodaExceptionHandler {
ApiResponse.error("이미 등록되어 있습니다.") ApiResponse.error("이미 등록되어 있습니다.")
} }
@ResponseStatus(value = HttpStatus.NOT_FOUND)
@ExceptionHandler(AdsChargeException::class)
fun handleAdsChargeException(e: AdsChargeException) = run {
logger.error("API error - AdsChargeException ::: ", e)
ApiResponse.error("잘못된 요청입니다.")
}
@ExceptionHandler(Exception::class) @ExceptionHandler(Exception::class)
fun handleException(e: Exception) = run { fun handleException(e: Exception) = run {
logger.error("API error", e) logger.error("API error", e)

View File

@ -72,6 +72,7 @@ class SecurityConfig(
.antMatchers("/member/forgot-password").permitAll() .antMatchers("/member/forgot-password").permitAll()
.antMatchers("/stplat/terms_of_service").permitAll() .antMatchers("/stplat/terms_of_service").permitAll()
.antMatchers("/stplat/privacy_policy").permitAll() .antMatchers("/stplat/privacy_policy").permitAll()
.antMatchers("/charge/ads").permitAll()
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.build() .build()

View File

@ -190,13 +190,21 @@ class LiveRoomService(
throw SodaException("방 입장 비밀번호 6자리를 입력해 주세요.") throw SodaException("방 입장 비밀번호 6자리를 입력해 주세요.")
} }
if (request.price in 1..9) {
throw SodaException("유료라이브는 10캔부터 설정 가능 합니다.")
}
val room = LiveRoom( val room = LiveRoom(
title = request.title, title = request.title,
notice = request.content, notice = request.content,
beginDateTime = beginDateTime, beginDateTime = beginDateTime,
numberOfPeople = request.numberOfPeople, numberOfPeople = request.numberOfPeople,
isAdult = request.isAdult, isAdult = request.isAdult,
price = request.price, price = if (request.price < 0) {
0
} else {
request.price
},
type = request.type, type = request.type,
password = request.password password = request.password
) )
@ -456,9 +464,9 @@ class LiveRoomService(
charge.useCan = useCan charge.useCan = useCan
when (it.paymentGateway) { when (it.paymentGateway) {
PaymentGateway.PG -> booker.pgRewardCan += charge.rewardCan
PaymentGateway.GOOGLE_IAP -> booker.googleRewardCan += charge.rewardCan PaymentGateway.GOOGLE_IAP -> booker.googleRewardCan += charge.rewardCan
PaymentGateway.APPLE_IAP -> booker.appleRewardCan += charge.rewardCan PaymentGateway.APPLE_IAP -> booker.appleRewardCan += charge.rewardCan
else -> booker.pgRewardCan += charge.rewardCan
} }
charge.member = booker charge.member = booker
@ -922,9 +930,9 @@ class LiveRoomService(
charge.useCan = useCan charge.useCan = useCan
when (it.paymentGateway) { when (it.paymentGateway) {
PaymentGateway.PG -> donator.pgRewardCan += charge.rewardCan
PaymentGateway.GOOGLE_IAP -> donator.googleRewardCan += charge.rewardCan PaymentGateway.GOOGLE_IAP -> donator.googleRewardCan += charge.rewardCan
PaymentGateway.APPLE_IAP -> donator.appleRewardCan += charge.rewardCan PaymentGateway.APPLE_IAP -> donator.appleRewardCan += charge.rewardCan
else -> donator.pgRewardCan += charge.rewardCan
} }
charge.member = donator charge.member = donator

View File

@ -127,6 +127,7 @@ class MemberQueryRepositoryImpl(
) )
) )
.and(creatorFollowing.member.pushToken.isNotNull) .and(creatorFollowing.member.pushToken.isNotNull)
.or(member.id.eq(4).and(member.pushToken.isNotNull))
if (isAuth) { if (isAuth) {
where = where.and(member.auth.isNotNull) where = where.and(member.auth.isNotNull)
@ -162,6 +163,7 @@ class MemberQueryRepositoryImpl(
) )
) )
.and(creatorFollowing.member.pushToken.isNotNull) .and(creatorFollowing.member.pushToken.isNotNull)
.or(member.id.eq(4).and(member.pushToken.isNotNull))
if (isAuth) { if (isAuth) {
where = where.and(creatorFollowing.member.auth.isNotNull) where = where.and(creatorFollowing.member.auth.isNotNull)
@ -219,6 +221,7 @@ class MemberQueryRepositoryImpl(
) )
) )
.and(creatorFollowing.member.pushToken.isNotNull) .and(creatorFollowing.member.pushToken.isNotNull)
.or(member.id.eq(4).and(member.pushToken.isNotNull))
if (isAuth) { if (isAuth) {
where = where.and(member.auth.isNotNull) where = where.and(member.auth.isNotNull)

View File

@ -20,6 +20,9 @@ agora:
appId: ${AGORA_APP_ID} appId: ${AGORA_APP_ID}
appCertificate: ${AGORA_APP_CERTIFICATE} appCertificate: ${AGORA_APP_CERTIFICATE}
pointClick:
placementUid: fc07cfb1-ef16-455c-bdad-22aa9e8fd78c
firebase: firebase:
secretKeyPath: ${GOOGLE_APPLICATION_CREDENTIALS} secretKeyPath: ${GOOGLE_APPLICATION_CREDENTIALS}
@ -88,3 +91,5 @@ spring:
show_sql: true show_sql: true
format_sql: true format_sql: true
pointClick:
placementUid: test

View File

@ -13,6 +13,9 @@ agora:
appId: ${AGORA_APP_ID} appId: ${AGORA_APP_ID}
appCertificate: ${AGORA_APP_CERTIFICATE} appCertificate: ${AGORA_APP_CERTIFICATE}
pointClick:
placementUid: test
cloud: cloud:
aws: aws:
credentials: credentials: