Skip to content

Commit

Permalink
fix: change pose snapshot ws event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Sep 4, 2024
1 parent 9ef529c commit f5b4402
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<GroupUserScore> {
return withContext(Dispatchers.IO) {
Expand Down Expand Up @@ -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) {
Expand All @@ -77,11 +76,9 @@ class GroupUserScoreService(
}
}

txTemplates.writer.coExecuteOrNull {
return txTemplates.writer.coExecute {
saveSync(createOrUpdateGroupUserScore)
}

wsHandler.launchSendEvent(groupUser.groupId)
}

suspend fun findAllByUids(uids: List<Long>): List<GroupUserScore> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit f5b4402

Please sign in to comment.