diff --git a/core/src/main/kotlin/timetables/dto/TimetableThemeDto.kt b/core/src/main/kotlin/timetables/dto/TimetableThemeDto.kt index 88105407..396930a6 100644 --- a/core/src/main/kotlin/timetables/dto/TimetableThemeDto.kt +++ b/core/src/main/kotlin/timetables/dto/TimetableThemeDto.kt @@ -4,6 +4,7 @@ import com.wafflestudio.snu4t.common.enum.BasicThemeType import com.wafflestudio.snu4t.timetables.data.ColorSet import com.wafflestudio.snu4t.timetables.data.TimetableTheme import com.wafflestudio.snu4t.timetables.service.toBasicThemeType +import com.wafflestudio.snu4t.timetables.service.toIdForTimetable data class TimetableThemeDto( val id: String?, @@ -17,7 +18,7 @@ data class TimetableThemeDto( fun TimetableThemeDto(timetableTheme: TimetableTheme) = with(timetableTheme) { TimetableThemeDto( - id = if (isCustom) id else null, + id = toIdForTimetable(), theme = toBasicThemeType(), name = name, colors = colors, diff --git a/core/src/main/kotlin/timetables/service/TimetableService.kt b/core/src/main/kotlin/timetables/service/TimetableService.kt index eb5e51a2..8a117845 100644 --- a/core/src/main/kotlin/timetables/service/TimetableService.kt +++ b/core/src/main/kotlin/timetables/service/TimetableService.kt @@ -69,7 +69,7 @@ class TimetableServiceImpl( semester = timetableRequest.semester, title = timetableRequest.title, theme = defaultTheme.toBasicThemeType(), - themeId = defaultTheme?.id, + themeId = defaultTheme.toIdForTimetable(), isPrimary = timetableRepository .findAllByUserIdAndYearAndSemester(userId, timetableRequest.year, timetableRequest.semester) .toList() @@ -122,7 +122,7 @@ class TimetableServiceImpl( val theme = timetableThemeService.getTheme(userId, themeId, basicThemeType) timetable.theme = theme.toBasicThemeType() - timetable.themeId = theme.id + timetable.themeId = theme.toIdForTimetable() val colorCount = if (theme.isCustom) requireNotNull(theme.colors).size else BasicThemeType.COLOR_COUNT timetable.lectures.forEachIndexed { index, lecture -> @@ -161,7 +161,7 @@ class TimetableServiceImpl( semester = coursebook.semester, title = "나의 시간표", theme = defaultTheme.toBasicThemeType(), - themeId = defaultTheme?.id, + themeId = defaultTheme.toIdForTimetable(), ) timetableRepository.save(timetable) } diff --git a/core/src/main/kotlin/timetables/service/TimetableThemeService.kt b/core/src/main/kotlin/timetables/service/TimetableThemeService.kt index 589d840f..e557be6f 100644 --- a/core/src/main/kotlin/timetables/service/TimetableThemeService.kt +++ b/core/src/main/kotlin/timetables/service/TimetableThemeService.kt @@ -238,8 +238,7 @@ class TimetableThemeServiceImpl( val theme = getTheme(timetable.userId, timetable.themeId) val alreadyUsedColors = timetable.lectures.map { requireNotNull(it.color) } - val colors = requireNotNull(theme.colors) { "theme.colors 가 null - userId: ${timetable.userId}, timetableId: ${timetable.id}, themeId: ${theme.id}" } - val colorToCount = colors.associateWith { color -> alreadyUsedColors.count { it == color } } + val colorToCount = requireNotNull(theme.colors).associateWith { color -> alreadyUsedColors.count { it == color } } val minCount = colorToCount.minOf { it.value } 0 to colorToCount.entries.filter { (_, count) -> count == minCount }.map { it.key }.random() @@ -248,3 +247,4 @@ class TimetableThemeServiceImpl( } fun TimetableTheme?.toBasicThemeType() = if (this == null || isCustom) BasicThemeType.SNUTT else requireNotNull(BasicThemeType.from(name)) +fun TimetableTheme?.toIdForTimetable() = if (this == null || isCustom.not()) null else id