From 8ca58a43554f8fa034175c2ef3577d118ab196d0 Mon Sep 17 00:00:00 2001 From: Davin Byeon Date: Sat, 2 Mar 2024 17:02:40 +0900 Subject: [PATCH] =?UTF-8?q?default=20theme=20=EA=B0=9C=EB=85=90=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=20(#232)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../timetables/repository/TimetableThemeRepository.kt | 2 +- .../kotlin/timetables/service/TimetableThemeService.kt | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/main/kotlin/timetables/repository/TimetableThemeRepository.kt b/core/src/main/kotlin/timetables/repository/TimetableThemeRepository.kt index 645749b7..e5c91d00 100644 --- a/core/src/main/kotlin/timetables/repository/TimetableThemeRepository.kt +++ b/core/src/main/kotlin/timetables/repository/TimetableThemeRepository.kt @@ -8,7 +8,7 @@ interface TimetableThemeRepository : CoroutineCrudRepository + suspend fun findByUserIdAndIsCustomTrueOrderByUpdatedAtDesc(userId: String): List suspend fun existsByUserIdAndName(userId: String, name: String): Boolean } diff --git a/core/src/main/kotlin/timetables/service/TimetableThemeService.kt b/core/src/main/kotlin/timetables/service/TimetableThemeService.kt index e557be6f..eac96de4 100644 --- a/core/src/main/kotlin/timetables/service/TimetableThemeService.kt +++ b/core/src/main/kotlin/timetables/service/TimetableThemeService.kt @@ -1,7 +1,6 @@ package com.wafflestudio.snu4t.timetables.service import com.wafflestudio.snu4t.common.enum.BasicThemeType -import com.wafflestudio.snu4t.common.exception.DefaultThemeDeleteErrorException import com.wafflestudio.snu4t.common.exception.DuplicateThemeNameException import com.wafflestudio.snu4t.common.exception.InvalidThemeColorCountException import com.wafflestudio.snu4t.common.exception.InvalidThemeTypeException @@ -49,7 +48,7 @@ class TimetableThemeServiceImpl( } override suspend fun getThemes(userId: String): List { - val customThemes = timetableThemeRepository.findByUserIdAndIsCustomTrueOrderByCreatedAtDesc(userId) + val customThemes = timetableThemeRepository.findByUserIdAndIsCustomTrueOrderByUpdatedAtDesc(userId) val defaultTheme = getDefaultTheme(userId) val basicThemes = BasicThemeType.values().map { @@ -111,7 +110,6 @@ class TimetableThemeServiceImpl( override suspend fun deleteTheme(userId: String, themeId: String) { val theme = getCustomTheme(userId, themeId) - if (theme.isDefault) throw DefaultThemeDeleteErrorException val timetables = timetableRepository.findByUserIdAndThemeId(userId, themeId) @@ -192,7 +190,8 @@ class TimetableThemeServiceImpl( } override suspend fun getDefaultTheme(userId: String): TimetableTheme? { - return timetableThemeRepository.findByUserIdAndIsDefaultTrue(userId) + val customThemes = timetableThemeRepository.findByUserIdAndIsCustomTrueOrderByUpdatedAtDesc(userId) + return customThemes.firstOrNull() ?: buildTimetableTheme(userId, BasicThemeType.SNUTT, isDefault = true) } override suspend fun getTheme(userId: String, themeId: String?, basicThemeType: BasicThemeType?): TimetableTheme {