Skip to content

Commit 287376e

Browse files
authored
비즈니스 로직에 트랜잭션을 추가한다. (#79)
fix: add transactions
1 parent 3bea188 commit 287376e

File tree

6 files changed

+17
-0
lines changed

6 files changed

+17
-0
lines changed

domain/src/main/kotlin/com/gotchai/domain/auth/adapter/in/AuthCommandService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class AuthCommandService(
4444
@Value("\${jwt.refresh-token-expiration}")
4545
private val refreshTokenExpiration: Duration
4646
) : AuthCommandUseCase {
47+
@Transactional
4748
override fun login(
4849
deviceId: String?,
4950
command: LoginCommand

domain/src/main/kotlin/com/gotchai/domain/badge/adapter/in/BadgeQueryService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ import com.gotchai.domain.badge.port.`in`.BadgeQueryUseCase
77
import com.gotchai.domain.badge.port.out.BadgeQueryPort
88
import com.gotchai.domain.badge.port.out.UserBadgeQueryPort
99
import org.springframework.stereotype.Service
10+
import org.springframework.transaction.annotation.Transactional
1011

1112
@Service
1213
class BadgeQueryService(
1314
private val badgeQueryPort: BadgeQueryPort,
1415
private val userBadgeQueryPort: UserBadgeQueryPort
1516
) : BadgeQueryUseCase {
17+
@Transactional(readOnly = true)
1618
override fun getBadgeById(badgeId: Long): Badge =
1719
badgeQueryPort.getBadgeById(badgeId)
1820
?: throw BadgeNotFoundException()
1921

22+
@Transactional(readOnly = true)
2023
override fun getMyBadges(userId: Long): List<Badge> {
2124
val userBadges = userBadgeQueryPort.getUserBadgesByUserId(userId)
2225
val badges =
@@ -26,6 +29,7 @@ class BadgeQueryService(
2629
return badges
2730
}
2831

32+
@Transactional(readOnly = true)
2933
override fun getBadgeByExamIdAndTier(
3034
examId: Long,
3135
tier: Tier

domain/src/main/kotlin/com/gotchai/domain/exam/adapter/in/ExamQueryService.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,29 @@ import com.gotchai.domain.exam.port.out.ExamHistoryQueryPort
77
import com.gotchai.domain.exam.port.out.ExamQueryPort
88
import com.gotchai.domain.quiz.port.out.QuizQueryPort
99
import org.springframework.stereotype.Service
10+
import org.springframework.transaction.annotation.Transactional
1011

1112
@Service
1213
class ExamQueryService(
1314
private val examQueryPort: ExamQueryPort,
1415
private val examHistoryQueryPort: ExamHistoryQueryPort,
1516
private val quizQueryPort: QuizQueryPort
1617
) : ExamQueryUseCase {
18+
@Transactional(readOnly = true)
1719
override fun getExamById(examId: Long): Exam = examQueryPort.getExamById(examId) ?: throw ExamNotFoundException()
1820

21+
@Transactional(readOnly = true)
1922
override fun getExams(): List<Exam> = examQueryPort.getExams()
2023

24+
@Transactional(readOnly = true)
2125
override fun getExamsByUserId(userId: Long): List<Exam> {
2226
val examHistories = examHistoryQueryPort.getExamHistoriesByUserIdAndSolvedTrue(userId)
2327
val exams = examQueryPort.getExamsByInIn(examHistories.map { it.id })
2428

2529
return exams
2630
}
2731

32+
@Transactional(readOnly = true)
2833
override fun getExamParticipantCountById(examId: Long): Int =
2934
examHistoryQueryPort
3035
.getExamHistoriesByExamIdAndSolvedTrue(examId)

domain/src/main/kotlin/com/gotchai/domain/quiz/adapter/in/QuizQueryService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import com.gotchai.domain.quiz.port.`in`.QuizQueryUseCase
77
import com.gotchai.domain.quiz.port.out.QuizPickQueryPort
88
import com.gotchai.domain.quiz.port.out.QuizQueryPort
99
import org.springframework.stereotype.Service
10+
import org.springframework.transaction.annotation.Transactional
1011

1112
@Service
1213
class QuizQueryService(
1314
private val quizQueryPort: QuizQueryPort,
1415
private val quizPickQueryPort: QuizPickQueryPort
1516
) : QuizQueryUseCase {
17+
@Transactional(readOnly = true)
1618
override fun getQuizById(quizId: Long): GetQuizResult {
1719
val quiz = quizQueryPort.getQuizById(quizId) ?: throw QuizNotFoundException()
1820
val quizPicks = quizPickQueryPort.getQuizPicksByQuizId(quiz.id)

domain/src/main/kotlin/com/gotchai/domain/user/adapter/in/ProfileQueryService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import com.gotchai.domain.user.exception.ProfileNotFoundException
55
import com.gotchai.domain.user.port.`in`.ProfileQueryUseCase
66
import com.gotchai.domain.user.port.out.ProfileQueryPort
77
import org.springframework.stereotype.Service
8+
import org.springframework.transaction.annotation.Transactional
89

910
@Service
1011
class ProfileQueryService(
1112
private val profileQueryPort: ProfileQueryPort
1213
) : ProfileQueryUseCase {
14+
@Transactional(readOnly = true)
1315
override fun getProfileByUserId(userId: Long): Profile? =
1416
profileQueryPort.getProfileByUserId(userId) ?: throw ProfileNotFoundException()
1517
}

storage/rdb/src/main/kotlin/com/gotchai/storage/rdb/user/adapter/out/UserQueryAdapter.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ package com.gotchai.storage.rdb.user.adapter.out
33
import com.gotchai.domain.user.entity.User
44
import com.gotchai.domain.user.port.out.UserQueryPort
55
import com.gotchai.storage.rdb.global.annotation.Adapter
6+
import com.gotchai.storage.rdb.global.annotation.ReadOnlyTransactional
67
import com.gotchai.storage.rdb.user.repository.UserJpaRepository
78
import org.springframework.data.repository.findByIdOrNull
89

910
@Adapter
1011
class UserQueryAdapter(
1112
private val userRepository: UserJpaRepository
1213
) : UserQueryPort {
14+
@ReadOnlyTransactional
1315
override fun getUserById(id: Long): User? =
1416
userRepository
1517
.findByIdOrNull(id)
1618
?.toUser()
1719

20+
@ReadOnlyTransactional
1821
override fun getUserByEmail(email: String): User? =
1922
userRepository
2023
.findByEmail(email)

0 commit comments

Comments
 (0)