fix: FOREIGN KEY constraint failed
This commit is contained in:
@@ -42,7 +42,7 @@ interface ScheduleDao {
|
||||
suspend fun trim(groupId: String, keep: Int)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertDays(days: List<DayEntity>)
|
||||
suspend fun insertDays(days: List<DayEntity>): List<Long>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertLessons(lessons: List<LessonEntity>)
|
||||
|
||||
@@ -112,11 +112,8 @@ class ScheduleRepositoryImpl(
|
||||
private suspend fun replaceDays(scheduleId: Long, days: List<Day>) {
|
||||
scheduleDao.deleteDaysForSchedule(scheduleId)
|
||||
val dayEntities = days.map { DayEntity(scheduleId = scheduleId, date = it.date.toEpochDay()) }
|
||||
val dayIdByDate = mutableMapOf<LocalDate, Long>()
|
||||
scheduleDao.insertDays(dayEntities)
|
||||
for (day in dayEntities) {
|
||||
dayIdByDate[LocalDate.ofEpochDay(day.date)] = day.id
|
||||
}
|
||||
val dayIds = scheduleDao.insertDays(dayEntities)
|
||||
val dayIdByDate = dayEntities.zip(dayIds).associate { (day, id) -> LocalDate.ofEpochDay(day.date) to id }
|
||||
val lessons = days.flatMap { day ->
|
||||
day.intervals.flatMapIndexed { slotIndex, slot ->
|
||||
slot.lessons.mapIndexed { lessonIndex, lesson ->
|
||||
|
||||
Reference in New Issue
Block a user