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

Reviewed-on: #19
This commit is contained in:
klaus 2023-08-28 08:54:08 +00:00
commit 60257c4ef4
4 changed files with 84 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package kr.co.vividnext.sodalive.content.comment package kr.co.vividnext.sodalive.content.comment
import com.querydsl.jpa.impl.JPAQueryFactory import com.querydsl.jpa.impl.JPAQueryFactory
import kr.co.vividnext.sodalive.content.QAudioContent.audioContent
import kr.co.vividnext.sodalive.content.comment.QAudioContentComment.audioContentComment import kr.co.vividnext.sodalive.content.comment.QAudioContentComment.audioContentComment
import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository import org.springframework.stereotype.Repository
@ -28,6 +29,8 @@ interface AudioContentCommentQueryRepository {
offset: Long, offset: Long,
limit: Int limit: Int
): List<GetAudioContentCommentListItem> ): List<GetAudioContentCommentListItem>
fun findPushTokenByContentCommentId(contentCommentId: Long): FindPushTokenByContentCommentIdResponse?
} }
@Repository @Repository
@ -138,4 +141,28 @@ class AudioContentCommentQueryRepositoryImpl(
} }
.toList() .toList()
} }
override fun findPushTokenByContentCommentId(contentCommentId: Long): FindPushTokenByContentCommentIdResponse? {
val response = queryFactory
.selectFrom(audioContentComment)
.innerJoin(audioContentComment.audioContent, audioContent)
.where(audioContentComment.id.eq(contentCommentId))
.fetchFirst()
return if (response == null) {
null
} else {
if (response.parent != null) {
FindPushTokenByContentCommentIdResponse(
pushToken = response.parent!!.member!!.pushToken ?: "",
container = response.parent!!.member!!.container
)
} else {
FindPushTokenByContentCommentIdResponse(
pushToken = response.audioContent!!.member!!.pushToken ?: "",
container = response.audioContent!!.member!!.container
)
}
}
}
} }

View File

@ -2,8 +2,11 @@ package kr.co.vividnext.sodalive.content.comment
import kr.co.vividnext.sodalive.common.SodaException import kr.co.vividnext.sodalive.common.SodaException
import kr.co.vividnext.sodalive.content.AudioContentRepository import kr.co.vividnext.sodalive.content.AudioContentRepository
import kr.co.vividnext.sodalive.fcm.FcmEvent
import kr.co.vividnext.sodalive.fcm.FcmEventType
import kr.co.vividnext.sodalive.member.Member import kr.co.vividnext.sodalive.member.Member
import org.springframework.beans.factory.annotation.Value import org.springframework.beans.factory.annotation.Value
import org.springframework.context.ApplicationEventPublisher
import org.springframework.data.domain.Pageable import org.springframework.data.domain.Pageable
import org.springframework.data.repository.findByIdOrNull import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
@ -14,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional
class AudioContentCommentService( class AudioContentCommentService(
private val repository: AudioContentCommentRepository, private val repository: AudioContentCommentRepository,
private val audioContentRepository: AudioContentRepository, private val audioContentRepository: AudioContentRepository,
private val applicationEventPublisher: ApplicationEventPublisher,
@Value("\${cloud.aws.cloud-front.host}") @Value("\${cloud.aws.cloud-front.host}")
private val cloudFrontHost: String private val cloudFrontHost: String
@ -38,6 +42,24 @@ class AudioContentCommentService(
} }
repository.save(audioContentComment) repository.save(audioContentComment)
applicationEventPublisher.publishEvent(
FcmEvent(
type = FcmEventType.CREATE_CONTENT_COMMENT,
title = if (parent != null) {
parent.member!!.nickname
} else {
member.nickname
},
message = if (parent != null) {
"댓글에 답글을 달았습니다.: ${audioContent.title}"
} else {
"콘텐츠에 댓글을 달았습니다.: ${audioContent.title}"
},
contentId = audioContentId,
contentCommentId = audioContentComment.id!!
)
)
} }
@Transactional @Transactional

View File

@ -0,0 +1,6 @@
package kr.co.vividnext.sodalive.content.comment
data class FindPushTokenByContentCommentIdResponse(
val pushToken: String,
val container: String
)

View File

@ -1,12 +1,15 @@
package kr.co.vividnext.sodalive.fcm package kr.co.vividnext.sodalive.fcm
import kr.co.vividnext.sodalive.content.comment.AudioContentCommentRepository
import kr.co.vividnext.sodalive.member.MemberRepository import kr.co.vividnext.sodalive.member.MemberRepository
import org.springframework.context.event.EventListener
import org.springframework.scheduling.annotation.Async import org.springframework.scheduling.annotation.Async
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Propagation
import org.springframework.transaction.annotation.Transactional
import org.springframework.transaction.event.TransactionalEventListener
enum class FcmEventType { enum class FcmEventType {
ALL, INDIVIDUAL, CREATE_LIVE, START_LIVE, UPLOAD_CONTENT, SEND_MESSAGE, CHANGE_NOTICE ALL, INDIVIDUAL, CREATE_LIVE, START_LIVE, UPLOAD_CONTENT, SEND_MESSAGE, CHANGE_NOTICE, CREATE_CONTENT_COMMENT
} }
class FcmEvent( class FcmEvent(
@ -19,16 +22,19 @@ class FcmEvent(
val roomId: Long? = null, val roomId: Long? = null,
val contentId: Long? = null, val contentId: Long? = null,
val messageId: Long? = null, val messageId: Long? = null,
val creatorId: Long? = null val creatorId: Long? = null,
val contentCommentId: Long? = null
) )
@Component @Component
class FcmSendListener( class FcmSendListener(
private val pushService: FcmService, private val pushService: FcmService,
private val memberRepository: MemberRepository private val memberRepository: MemberRepository,
private val contentCommentRepository: AudioContentCommentRepository
) { ) {
@Async @Async
@EventListener @TransactionalEventListener
@Transactional(propagation = Propagation.REQUIRES_NEW)
fun send(fcmEvent: FcmEvent) { fun send(fcmEvent: FcmEvent) {
when (fcmEvent.type) { when (fcmEvent.type) {
FcmEventType.ALL -> { FcmEventType.ALL -> {
@ -189,6 +195,24 @@ class FcmSendListener(
} }
} }
} }
FcmEventType.CREATE_CONTENT_COMMENT -> {
if (fcmEvent.contentCommentId != null && fcmEvent.contentId != null) {
val response = contentCommentRepository.findPushTokenByContentCommentId(
contentCommentId = fcmEvent.contentCommentId
)
if (response != null) {
pushService.send(
tokens = listOf(response.pushToken),
title = fcmEvent.title,
message = fcmEvent.message,
container = response.container,
contentId = fcmEvent.contentId
)
}
}
}
} }
} }
} }