cloudroam
2025-04-10 5fc9567cfa6b6beee4f52a9f835f304865d693e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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)
    }