2026-09-02 23:47:00 +03:00
|
|
|
package agzam.vyatsu.data.local
|
|
|
|
|
|
|
|
|
|
import androidx.room.Dao
|
|
|
|
|
import androidx.room.Insert
|
|
|
|
|
import androidx.room.OnConflictStrategy
|
|
|
|
|
import androidx.room.Query
|
|
|
|
|
import kotlinx.coroutines.flow.Flow
|
|
|
|
|
|
|
|
|
|
@Dao
|
|
|
|
|
interface ScheduleDao {
|
|
|
|
|
|
2026-09-03 19:41:26 +03:00
|
|
|
@Query("SELECT * FROM schedules WHERE groupId = :groupId ORDER BY weekStart DESC")
|
|
|
|
|
fun observeSchedules(groupId: String): Flow<List<ScheduleEntity>>
|
2026-09-02 23:47:00 +03:00
|
|
|
|
2026-09-03 19:41:26 +03:00
|
|
|
@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)
|
2026-09-02 23:47:00 +03:00
|
|
|
|
|
|
|
|
@Query("DELETE FROM schedules WHERE groupId = :groupId")
|
2026-09-03 19:41:26 +03:00
|
|
|
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)
|
2026-09-03 20:41:03 +03:00
|
|
|
suspend fun insertDays(days: List<DayEntity>): List<Long>
|
2026-09-03 19:41:26 +03:00
|
|
|
|
|
|
|
|
@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>>
|
2026-09-02 23:47:00 +03:00
|
|
|
}
|