Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat/#450] v2 jpa 설정 추가 #461

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/src/main/kotlin/com/few/api/config/ApiJpaConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.few.api.config

import org.springframework.context.annotation.Configuration
import repo.jpa.EnableJpaRepositories

@Configuration
@EnableJpaRepositories(basePackages = [ApiConfig.BASE_PACKAGE])
class ApiJpaConfig
Comment on lines +6 to +8
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

도메인 모듈을 추가하고 해당 모듈에서 JPA 설정을 해야한다면 위와 같이 설정하면 됩니다.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.few.api.domain.problem.repo.command.InsertProblemsCommand
import com.few.api.domain.problem.repo.support.Content
import com.few.api.domain.problem.repo.support.Contents
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional
import storage.document.PutDocumentProvider
import java.io.File
import java.time.LocalDateTime
Expand All @@ -41,7 +41,7 @@ class AddArticleUseCase(
private val getUrlService: GetUrlService,
private val adminArticleMainCardService: AdminArticleMainCardService,
) {
@Transactional
@DataSourceTransactional
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JPA가 추가되어 TX가 2개가 생겨 명확히 구분이 필요하여 수정하였습니다.

fun execute(useCaseIn: AddArticleUseCaseIn): AddArticleUseCaseOut {
val writerRecord =
memberDao.selectMemberByEmail(SelectMemberByEmailQuery(useCaseIn.writerEmail))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import com.few.api.domain.common.exception.InsertException
import com.few.api.domain.workbook.repo.WorkbookDao
import com.few.api.domain.workbook.repo.command.InsertWorkBookCommand
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional

@Component
class AddWorkbookUseCase(
private val workbookDao: WorkbookDao,
) {
@Transactional
@DataSourceTransactional
fun execute(useCaseIn: AddWorkbookUseCaseIn): AddWorkbookUseCaseOut {
val workbookId =
workbookDao.insertWorkBook(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.few.api.domain.admin.utils.ObjectPathGenerator
import com.few.api.domain.common.exception.ExternalIntegrationException
import com.few.api.domain.common.exception.InsertException
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional
import storage.document.PutDocumentProvider
import java.io.File

Expand All @@ -21,7 +21,7 @@ class ConvertContentUseCase(
private val putDocumentService: PutDocumentProvider,
private val getUrlService: GetUrlService,
) {
@Transactional
@DataSourceTransactional
fun execute(useCaseIn: ConvertContentUseCaseIn): ConvertContentUseCaseOut {
val contentSource = useCaseIn.content

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import com.few.api.domain.admin.usecase.dto.MapArticleUseCaseIn
import com.few.api.domain.workbook.repo.WorkbookDao
import com.few.api.domain.workbook.repo.command.MapWorkBookToArticleCommand
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional

@Component
class MapArticleUseCase(
private val workbookDao: WorkbookDao,
private val adminArticleMainCardService: AdminArticleMainCardService,
) {
@Transactional
@DataSourceTransactional
fun execute(useCaseIn: MapArticleUseCaseIn) {
workbookDao.mapWorkBookToArticle(
MapWorkBookToArticleCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.few.api.domain.common.exception.InsertException
import com.sksamuel.scrimage.ImmutableImage
import com.sksamuel.scrimage.webp.WebpWriter
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional
import storage.image.PutImageProvider
import java.io.File

Expand All @@ -22,7 +22,7 @@ class PutImageUseCase(
private val putImageService: PutImageProvider,
private val getUrlService: GetUrlService,
) {
@Transactional
@DataSourceTransactional
fun execute(useCaseIn: PutImageUseCaseIn): PutImageUseCaseOut {
val imageSource = useCaseIn.source
val suffix = imageSource.originalFilename?.substringAfterLast(".") ?: "jpg"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.few.api.domain.common.vo.CategoryType
import io.github.oshai.kotlinlogging.KotlinLogging
import org.springframework.scheduling.annotation.Async
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional

@Component
class ArticleViewHisAsyncHandler(
Expand All @@ -19,7 +19,7 @@ class ArticleViewHisAsyncHandler(
private val log = KotlinLogging.logger {}

@Async(value = DATABASE_ACCESS_POOL)
@Transactional
@DataSourceTransactional
fun addArticleViewHis(
articleId: Long,
memberId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.few.api.domain.article.usecase.dto.*
import com.few.api.domain.common.exception.NotFoundException
import com.few.api.domain.common.vo.CategoryType
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional
import java.util.*
import kotlin.Comparator

Expand All @@ -22,7 +22,7 @@ class BrowseArticlesUseCase(
private val articleMainCardDao: ArticleMainCardDao,
private val articleDao: ArticleDao,
) {
@Transactional(readOnly = true)
@DataSourceTransactional(readOnly = true)
fun execute(useCaseIn: ReadArticlesUseCaseIn): ReadArticlesUseCaseOut {
/**
* 아티클 조회수 테이블에서 마지막 읽은 아티클 아이디, 카테고리를 기반으로 Offset(테이블 row 순위)을 구함
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import com.few.api.domain.article.usecase.dto.ReadArticleByEmailUseCaseIn
import com.few.api.domain.common.exception.NotFoundException
import com.few.api.domain.common.vo.EmailLogEventType
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional

@Component
class ReadArticleByEmailUseCase(
private val memberService: ArticleMemberService,
private val articleLogService: ArticleLogService,
) {
@Transactional
@DataSourceTransactional
fun execute(useCaseIn: ReadArticleByEmailUseCaseIn) {
val memberId =
memberService.readMemberByEmail(ReadMemberByEmailDto(useCaseIn.destination[0]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.few.api.domain.common.exception.NotFoundException
import com.few.api.domain.common.vo.CategoryType
import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional

@Component
class ReadArticleUseCase(
Expand All @@ -25,7 +25,7 @@ class ReadArticleUseCase(
private val articleViewCountTxCase: ArticleViewCountTxCase,
private val applicationEventPublisher: ApplicationEventPublisher,
) {
@Transactional(readOnly = true)
@DataSourceTransactional(readOnly = true)
fun execute(useCaseIn: ReadArticleUseCaseIn): ReadArticleUseCaseOut {
val articleRecord =
articleDao.selectArticleRecord(SelectArticleRecordQuery(useCaseIn.articleId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import com.few.api.domain.article.repo.command.ArticleViewCountCommand
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Isolation
import org.springframework.transaction.annotation.Propagation
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional

@Component
class ArticleViewCountTxCase(
private val articleViewCountDao: ArticleViewCountDao,
) {
@Transactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRES_NEW)
@DataSourceTransactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRES_NEW)
fun browseArticleViewCount(articleId: Long): Long =
(articleViewCountDao.selectArticleViewCount(ArticleViewCountCommand(articleId)) ?: 0L) + 1L
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.few.api.domain.batch.article.reader.WorkBookSubscriberReader
import com.few.api.domain.batch.article.writer.WorkBookSubscriberWriter
import com.few.api.domain.batch.log.ApiBatchCallExecutionService
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional

@Service
class ApiBatchSendArticleEmailService(
Expand All @@ -14,7 +14,7 @@ class ApiBatchSendArticleEmailService(
private val batchCallExecutionService: ApiBatchCallExecutionService,
private val objectMapper: ObjectMapper,
) {
@Transactional
@DataSourceTransactional
fun execute() {
val startTime = System.currentTimeMillis()
workBookSubscriberReader.execute().let { item ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.jooq.Condition
import org.jooq.DSLContext
import org.jooq.TableField
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.LocalTime
Expand All @@ -19,7 +19,7 @@ class WorkBookSubscriberReader(
private val dslContext: DSLContext,
) {
/** 구독 테이블에서 학습지를 구독하고 있는 회원의 정보를 조회한다.*/
@Transactional(readOnly = true)
@DataSourceTransactional(readOnly = true)
fun execute(): List<WorkBookSubscriberItem> {
val time = LocalTime.now(ZoneId.of("Asia/Seoul")).hour.let { LocalTime.of(it, 0, 0) }
val date = LocalDate.now(ZoneId.of("Asia/Seoul"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.jooq.DSLContext
import org.jooq.InsertSetMoreStep
import org.jooq.UpdateConditionStep
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional
import java.time.LocalDate
import java.time.LocalDateTime

Expand All @@ -35,7 +35,7 @@ class WorkBookSubscriberWriter(
/**
* 구독자들에게 이메일을 전송하고 진행률을 업데이트한다.
*/
@Transactional
@DataSourceTransactional
fun execute(items: List<WorkBookSubscriberItem>): Map<Any, Any> {
val memberIds = items.toMemberIds()
val targetWorkBookIds = items.toTargetWorkBookIds()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import com.few.api.domain.log.dto.AddApiLogUseCaseIn
import com.few.api.domain.log.repo.LogIfoDao
import com.few.api.domain.log.repo.command.InsertLogCommand
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional

@Component
class AddApiLogUseCase(
private val logIfoDao: LogIfoDao,
) {
@Transactional
@DataSourceTransactional
fun execute(useCaseIn: AddApiLogUseCaseIn) {
logIfoDao.insertLogIfo(InsertLogCommand(useCaseIn.history))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import com.few.api.domain.log.repo.query.SelectEventByMessageIdAndEventTypeQuery
import com.few.api.domain.member.repo.MemberDao
import com.few.api.domain.member.repo.query.SelectMemberByEmailQuery
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional

@Component
class AddEmailLogUseCase(
private val memberDao: MemberDao,
private val sendArticleEventHistoryDao: SendArticleEventHistoryDao,
) {
@Transactional
@DataSourceTransactional
fun execute(useCaseIn: AddEmailLogUseCaseIn) {
val (memberId, _, _, _) =
memberDao.selectMemberByEmail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import com.few.api.domain.member.service.dto.DeleteSubscriptionDto
import com.few.api.domain.subscription.repo.SubscriptionDao
import com.few.api.domain.subscription.repo.command.UpdateDeletedAtInAllSubscriptionCommand
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional

@Service
class MemberSubscriptionService(
private val subscriptionDao: SubscriptionDao,
) {
@Transactional
@DataSourceTransactional
fun deleteSubscription(dto: DeleteSubscriptionDto) {
subscriptionDao.updateDeletedAtInAllSubscription(
UpdateDeletedAtInAllSubscriptionCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import com.few.api.domain.member.service.dto.DeleteSubscriptionDto
import com.few.api.domain.member.usecase.dto.DeleteMemberUseCaseIn
import com.few.api.domain.member.usecase.dto.DeleteMemberUseCaseOut
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional

@Component
class DeleteMemberUseCase(
private val memberDao: MemberDao,
private val memberSubscriptionService: MemberSubscriptionService,
) {
@Transactional
@DataSourceTransactional
fun execute(useCaseIn: DeleteMemberUseCaseIn): DeleteMemberUseCaseOut {
memberDao.deleteMember(
DeleteMemberCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.few.api.domain.member.usecase.dto.SaveMemberUseCaseIn
import com.few.api.domain.member.usecase.dto.SaveMemberUseCaseOut
import com.few.api.domain.member.usecase.transaction.SaveMemberTxCase
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional
import security.encryptor.IdEncryptor
import java.net.URL

Expand All @@ -21,7 +21,7 @@ class SaveMemberUseCase(
private val idEncryption: IdEncryptor,
private val saveMemberTxCase: SaveMemberTxCase,
) {
@Transactional
@DataSourceTransactional
fun execute(useCaseIn: SaveMemberUseCaseIn): SaveMemberUseCaseOut {
/** email을 통해 가입 이력이 있는지 확인 */
val (headComment, subComment, memberId) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.few.api.domain.member.repo.command.UpdateMemberTypeCommand
import com.few.api.domain.member.usecase.dto.TokenUseCaseIn
import com.few.api.domain.member.usecase.dto.TokenUseCaseOut
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional
import security.Roles
import security.TokenGenerator
import security.TokenResolver
Expand All @@ -22,7 +22,7 @@ class TokenUseCase(
private val memberDao: MemberDao,
private val idEncryption: IdEncryptor,
) {
@Transactional
@DataSourceTransactional
fun execute(useCaseIn: TokenUseCaseIn): TokenUseCaseOut {
var isLogin = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.few.api.domain.member.repo.record.MemberIdAndIsDeletedRecord
import com.few.api.domain.member.usecase.dto.SaveMemberTxCaseIn
import com.few.api.domain.member.usecase.dto.SaveMemberTxCaseOut
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional

@Component
class SaveMemberTxCase(
Expand All @@ -22,7 +22,7 @@ class SaveMemberTxCase(
private const val SIGNUP_SUB_COMMENT = "가입하신 이메일 주소를 확인해주세요."
}

@Transactional
@DataSourceTransactional
fun execute(dto: SaveMemberTxCaseIn): SaveMemberTxCaseOut =
dto.record?.let { signUpBeforeMember ->
signUpBeforeMember.takeIf { it.isDeleted }?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import com.few.api.domain.problem.repo.query.SelectProblemsByArticleIdQuery
import com.few.api.domain.problem.usecase.dto.BrowseProblemsUseCaseIn
import com.few.api.domain.problem.usecase.dto.BrowseProblemsUseCaseOut
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional

@Component
class BrowseProblemsUseCase(
private val problemDao: ProblemDao,
) {
@Transactional(readOnly = true)
@DataSourceTransactional(readOnly = true)
fun execute(useCaseIn: BrowseProblemsUseCaseIn): BrowseProblemsUseCaseOut {
problemDao
.selectProblemsByArticleId(SelectProblemsByArticleIdQuery(useCaseIn.articleId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.few.api.domain.problem.service.dto.BrowseWorkbookIdAndProgressInDto
import com.few.api.domain.problem.usecase.dto.BrowseProblemsUseCaseOut
import com.few.api.domain.problem.usecase.dto.BrowseUndoneProblemsUseCaseIn
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import repo.jooq.DataSourceTransactional

@Component
class BrowseUndoneProblemsUseCase(
Expand All @@ -21,7 +21,7 @@ class BrowseUndoneProblemsUseCase(
private val problemArticleService: ProblemArticleService,
private val submitHistoryDao: SubmitHistoryDao,
) {
@Transactional(readOnly = true)
@DataSourceTransactional(readOnly = true)
fun execute(useCaseIn: BrowseUndoneProblemsUseCaseIn): BrowseProblemsUseCaseOut {
/**
* 유저가 구독한 워크북들에 속한 아티클 개수를 조회함
Expand Down
Loading
Loading