forked from agzam/vyatsu-schedule
refactor: database multi-period schedule storage
This commit is contained in:
@@ -8,15 +8,68 @@ import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface ScheduleDao {
|
||||
@Query("SELECT * FROM schedules WHERE groupId = :groupId")
|
||||
fun observe(groupId: String): Flow<ScheduleEntity?>
|
||||
|
||||
@Query("SELECT * FROM schedules WHERE groupId = :groupId")
|
||||
suspend fun get(groupId: String): ScheduleEntity?
|
||||
@Query("SELECT * FROM schedules WHERE groupId = :groupId ORDER BY weekStart DESC")
|
||||
fun observeSchedules(groupId: String): Flow<List<ScheduleEntity>>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsert(entity: ScheduleEntity)
|
||||
@Query("SELECT * FROM schedules WHERE groupId = :groupId ORDER BY weekStart DESC")
|
||||
suspend fun getSchedules(groupId: String): List<ScheduleEntity>
|
||||
|
||||
@Query("DELETE FROM days WHERE scheduleId = :scheduleId")
|
||||
suspend fun deleteDaysForSchedule(scheduleId: Long)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.ABORT)
|
||||
suspend fun insertSchedule(schedule: ScheduleEntity): Long
|
||||
|
||||
@Query("DELETE FROM schedules WHERE groupId = :groupId AND season = :season AND weekStart = :weekStart")
|
||||
suspend fun deleteSchedule(groupId: String, season: String, weekStart: Long)
|
||||
|
||||
@Query("DELETE FROM schedules WHERE groupId = :groupId")
|
||||
suspend fun delete(groupId: String)
|
||||
suspend fun deleteAll(groupId: String)
|
||||
|
||||
@Query(
|
||||
"""
|
||||
DELETE FROM schedules
|
||||
WHERE groupId = :groupId
|
||||
AND id NOT IN (
|
||||
SELECT id FROM schedules
|
||||
WHERE groupId = :groupId
|
||||
ORDER BY weekStart DESC
|
||||
LIMIT :keep
|
||||
)
|
||||
"""
|
||||
)
|
||||
suspend fun trim(groupId: String, keep: Int)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertDays(days: List<DayEntity>)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertLessons(lessons: List<LessonEntity>)
|
||||
|
||||
@Query(
|
||||
"SELECT days.* FROM days INNER JOIN schedules ON schedules.id = days.scheduleId " +
|
||||
"WHERE schedules.groupId = :groupId ORDER BY days.date"
|
||||
)
|
||||
suspend fun getDaysForGroup(groupId: String): List<DayEntity>
|
||||
|
||||
@Query(
|
||||
"SELECT lessons.* FROM lessons INNER JOIN days ON days.id = lessons.dayId " +
|
||||
"INNER JOIN schedules ON schedules.id = days.scheduleId " +
|
||||
"WHERE schedules.groupId = :groupId ORDER BY lessons.date, lessons.slotIndex, lessons.lessonIndex"
|
||||
)
|
||||
suspend fun getLessonsForGroup(groupId: String): List<LessonEntity>
|
||||
|
||||
@Query(
|
||||
"SELECT days.* FROM days INNER JOIN schedules ON schedules.id = days.scheduleId " +
|
||||
"WHERE schedules.groupId = :groupId ORDER BY days.date"
|
||||
)
|
||||
fun observeDaysForGroup(groupId: String): Flow<List<DayEntity>>
|
||||
|
||||
@Query(
|
||||
"SELECT lessons.* FROM lessons INNER JOIN days ON days.id = lessons.dayId " +
|
||||
"INNER JOIN schedules ON schedules.id = days.scheduleId " +
|
||||
"WHERE schedules.groupId = :groupId ORDER BY lessons.date, lessons.slotIndex, lessons.lessonIndex"
|
||||
)
|
||||
fun observeLessonsForGroup(groupId: String): Flow<List<LessonEntity>>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user