Files
vyatsu-schedule/app/src/main/java/agzam/vyatsu/data/local/TeacherDao.kt
T

40 lines
1.4 KiB
Kotlin
Raw Normal View History

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 TeacherDao {
@Query("SELECT * FROM departments ORDER BY name")
fun observeDepartments(): Flow<List<DepartmentEntity>>
@Query("SELECT * FROM departments WHERE departmentId = :id")
suspend fun getDepartment(id: String): DepartmentEntity?
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(departments: List<DepartmentEntity>)
@Query("SELECT MAX(lastSyncedAt) FROM departments")
suspend fun maxSyncedAt(): Long?
@Query("SELECT DISTINCT faculty FROM departments ORDER BY faculty")
suspend fun getFaculties(): List<String>
@Query("DELETE FROM department_periods")
suspend fun deleteAllPeriods()
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertPeriods(periods: List<DepartmentPeriodEntity>)
@Query(
"SELECT * FROM department_periods WHERE weekStart <= :epochDay AND weekEnd >= :epochDay ORDER BY departmentId"
)
suspend fun getPeriodsForDate(epochDay: Long): List<DepartmentPeriodEntity>
@Query("SELECT * FROM department_periods WHERE departmentId = :departmentId ORDER BY weekStart")
suspend fun getPeriodsForDepartment(departmentId: String): List<DepartmentPeriodEntity>
}