package com.example.firstapp.database.repository
|
|
import android.content.Context
|
import com.example.firstapp.AppDatabase
|
import com.example.firstapp.database.dao.ReminderRecordDao
|
import com.example.firstapp.database.entity.ReminderRecord
|
import kotlinx.coroutines.flow.Flow
|
|
class ReminderRecordRepository(context: Context) {
|
private val reminderRecordDao: ReminderRecordDao = AppDatabase.getInstance(context).reminderRecordDao()
|
|
fun getAllRecords(): Flow<List<ReminderRecord>> = reminderRecordDao.getAllRecords()
|
|
fun getRecordsByStatus(status: Int): Flow<List<ReminderRecord>> =
|
reminderRecordDao.getRecordsByStatus(status)
|
|
suspend fun insertRecord(record: ReminderRecord): Long {
|
return reminderRecordDao.insertRecord(record)
|
}
|
|
suspend fun updateRecord(record: ReminderRecord) {
|
reminderRecordDao.updateRecord(record)
|
}
|
|
suspend fun deleteRecord(record: ReminderRecord) {
|
reminderRecordDao.deleteRecord(record)
|
}
|
|
suspend fun deleteRecordsByCategoryId(categoryId: Int) {
|
reminderRecordDao.deleteRecordsByCategoryId(categoryId)
|
}
|
|
suspend fun updateRecordStatus(recordId: Long, status: Int) {
|
reminderRecordDao.updateRecordStatus(recordId, status)
|
}
|
|
suspend fun getUnreadCount(status: Int): Int {
|
return reminderRecordDao.getUnreadCount(status)
|
}
|
}
|