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 +}