From f5b4402fa34342a77a2583fedd5bbff6bef97b28 Mon Sep 17 00:00:00 2001 From: DongGeon0908 Date: Wed, 4 Sep 2024 22:29:01 +0900 Subject: [PATCH] fix: change pose snapshot ws event handler --- .../domain/group/application/GroupUserScoreService.kt | 9 +++------ .../hero/alignlab/event/listener/PoseSnapshotListener.kt | 6 +++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupUserScoreService.kt b/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupUserScoreService.kt index 5b17b7e..1d21d03 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupUserScoreService.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupUserScoreService.kt @@ -1,11 +1,11 @@ package com.hero.alignlab.domain.group.application +import com.hero.alignlab.common.extension.coExecute import com.hero.alignlab.common.extension.coExecuteOrNull import com.hero.alignlab.config.database.TransactionTemplates import com.hero.alignlab.domain.group.domain.GroupUser import com.hero.alignlab.domain.group.domain.GroupUserScore import com.hero.alignlab.domain.group.infrastructure.GroupUserScoreRepository -import com.hero.alignlab.ws.handler.ReactiveGroupUserWebSocketHandler import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.springframework.stereotype.Service @@ -15,7 +15,6 @@ import org.springframework.transaction.annotation.Transactional class GroupUserScoreService( private val groupUserScoreRepository: GroupUserScoreRepository, private val txTemplates: TransactionTemplates, - private val wsHandler: ReactiveGroupUserWebSocketHandler, ) { suspend fun findAllByGroupId(groupId: Long): List { return withContext(Dispatchers.IO) { @@ -61,7 +60,7 @@ class GroupUserScoreService( } } - suspend fun createOrUpdateGroupUserScore(groupUser: GroupUser, score: Int) { + suspend fun createOrUpdateGroupUserScore(groupUser: GroupUser, score: Int): GroupUserScore { val groupUserScore = findByUidOrNull(groupUser.uid) val createOrUpdateGroupUserScore = when (groupUserScore == null) { @@ -77,11 +76,9 @@ class GroupUserScoreService( } } - txTemplates.writer.coExecuteOrNull { + return txTemplates.writer.coExecute { saveSync(createOrUpdateGroupUserScore) } - - wsHandler.launchSendEvent(groupUser.groupId) } suspend fun findAllByUids(uids: List): List { diff --git a/src/main/kotlin/com/hero/alignlab/event/listener/PoseSnapshotListener.kt b/src/main/kotlin/com/hero/alignlab/event/listener/PoseSnapshotListener.kt index 4a348ab..1e4f57e 100644 --- a/src/main/kotlin/com/hero/alignlab/event/listener/PoseSnapshotListener.kt +++ b/src/main/kotlin/com/hero/alignlab/event/listener/PoseSnapshotListener.kt @@ -11,6 +11,7 @@ import com.hero.alignlab.domain.pose.domain.PoseCount import com.hero.alignlab.domain.pose.domain.PoseKeyPointSnapshot import com.hero.alignlab.domain.pose.domain.vo.PoseType.Companion.BAD_POSE import com.hero.alignlab.event.model.LoadPoseSnapshot +import com.hero.alignlab.ws.handler.ReactiveGroupUserWebSocketHandler import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -26,6 +27,7 @@ class PoseSnapshotListener( private val groupUserScoreService: GroupUserScoreService, private val groupUserService: GroupUserService, private val txTemplates: TransactionTemplates, + private val wsHandler: ReactiveGroupUserWebSocketHandler, ) { @TransactionalEventListener fun handle(event: LoadPoseSnapshot) { @@ -69,7 +71,9 @@ class PoseSnapshotListener( toCreatedAt = to ).filter { model -> model.type in BAD_POSE }.sumOf { model -> model.count }.toInt() - groupUserScoreService.createOrUpdateGroupUserScore(this, score) + val groupUserScore = groupUserScoreService.createOrUpdateGroupUserScore(this, score) + + wsHandler.launchSendEvent(groupUserScore.groupId) } } }