From cf65ccf91548411818d29a233968265fcc9984ed Mon Sep 17 00:00:00 2001 From: pricelees Date: Wed, 17 Sep 2025 10:37:47 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=9E=85=EB=A0=A5=EB=90=9C=20Id=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=EB=A1=9C=20=ED=85=8C=EB=A7=88=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=8B=9C=20In=20=EC=BF=BC=EB=A6=AC=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roomescape/theme/business/ThemeService.kt | 23 ++++++------------- .../persistence/ThemeRepository.kt | 4 +++- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/roomescape/theme/business/ThemeService.kt b/src/main/kotlin/roomescape/theme/business/ThemeService.kt index 89492250..7ee4fb80 100644 --- a/src/main/kotlin/roomescape/theme/business/ThemeService.kt +++ b/src/main/kotlin/roomescape/theme/business/ThemeService.kt @@ -8,6 +8,7 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import roomescape.admin.business.AdminService import roomescape.common.config.next +import roomescape.common.dto.AuditInfo import roomescape.theme.exception.ThemeErrorCode import roomescape.theme.exception.ThemeException import roomescape.theme.infrastructure.persistence.ThemeEntity @@ -42,18 +43,9 @@ class ThemeService( } @Transactional(readOnly = true) - fun findThemesByIds(request: ThemeIdListRequest): ThemeInfoListResponse { + fun findAllInfosByIds(request: ThemeIdListRequest): ThemeInfoListResponse { log.info { "[ThemeService.findThemesByIds] 예약 페이지에서의 테마 목록 조회 시작: themeIds=${request.themeIds}" } - val result: MutableList = mutableListOf() - - for (id in request.themeIds) { - val theme: ThemeEntity? = themeRepository.findByIdOrNull(id) - if (theme == null) { - log.warn { "[ThemeService.findThemesByIds] id=${id} 인 테마 조회 실패" } - continue - } - result.add(theme) - } + val result: List = themeRepository.findAllByIdIn(request.themeIds) return result.toInfoListResponse().also { log.info { "[ThemeService.findThemesByIds] ${it.themes.size} / ${request.themeIds.size} 개 테마 조회 완료" } @@ -80,8 +72,9 @@ class ThemeService( val createdBy = adminService.findOperatorOrUnknown(theme.createdBy) val updatedBy = adminService.findOperatorOrUnknown(theme.updatedBy) + val audit = AuditInfo(theme.createdAt, createdBy, theme.updatedAt, updatedBy) - return theme.toAdminThemeDetailResponse(createdBy, updatedBy) + return theme.toAdminThemeDetailResponse(audit) .also { log.info { "[ThemeService.findAdminThemeDetail] 테마 상세 조회 완료: id=$id, name=${theme.name}" } } } @@ -91,9 +84,8 @@ class ThemeService( themeValidator.validateCanCreate(request) - val theme: ThemeEntity = themeRepository.save( - request.toEntity(tsidFactory.next()) - ) + val theme: ThemeEntity = request.toEntity(id = tsidFactory.next()) + .also { themeRepository.save(it) } return ThemeCreateResponse(theme.id).also { log.info { "[ThemeService.createTheme] 테마 생성 완료: id=${theme.id}, name=${theme.name}" } @@ -155,7 +147,6 @@ class ThemeService( } } - // ======================================== // Common (공통 메서드) // ======================================== diff --git a/src/main/kotlin/roomescape/theme/infrastructure/persistence/ThemeRepository.kt b/src/main/kotlin/roomescape/theme/infrastructure/persistence/ThemeRepository.kt index 8e55104b..25934626 100644 --- a/src/main/kotlin/roomescape/theme/infrastructure/persistence/ThemeRepository.kt +++ b/src/main/kotlin/roomescape/theme/infrastructure/persistence/ThemeRepository.kt @@ -9,4 +9,6 @@ interface ThemeRepository : JpaRepository { fun findActiveThemes(): List fun existsByName(name: String): Boolean -} \ No newline at end of file + + fun findAllByIdIn(themeIds: List): List +}