Coverage Summary for Class: NoteRepositoryImpl (com.stslex93.notes.core.notes.repository)
Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
NoteRepositoryImpl |
0%
(0/7)
|
|
0%
(0/16)
|
0%
(0/91)
|
NoteRepositoryImpl$Companion |
|
NoteRepositoryImpl$deleteNotesById$2 |
0%
(0/1)
|
|
0%
(0/1)
|
0%
(0/14)
|
NoteRepositoryImpl$getNote$2 |
0%
(0/1)
|
|
0%
(0/1)
|
0%
(0/16)
|
NoteRepositoryImpl$getNoteFlow$$inlined$map$1 |
0%
(0/2)
|
|
NoteRepositoryImpl$getNoteFlow$$inlined$map$1$2 |
0%
(0/1)
|
|
NoteRepositoryImpl$getNoteFlow$$inlined$map$1$2$1 |
|
NoteRepositoryImpl$insert$2 |
0%
(0/1)
|
|
0%
(0/1)
|
0%
(0/15)
|
NoteRepositoryImpl$searchNotes$$inlined$map$1 |
0%
(0/2)
|
|
NoteRepositoryImpl$searchNotes$$inlined$map$1$2 |
0%
(0/1)
|
|
NoteRepositoryImpl$searchNotes$$inlined$map$1$2$1 |
|
NoteRepositoryImpl$searchNotes$2$1 |
0%
(0/1)
|
|
0%
(0/1)
|
0%
(0/7)
|
Total |
0%
(0/17)
|
|
0%
(0/20)
|
0%
(0/143)
|
package com.stslex93.notes.core.notes.repository
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.map
import com.stslex93.notes.core.database.note.NoteDao
import com.stslex93.notes.core.notes.model.NoteDataModel
import com.stslex93.notes.core.notes.model.toData
import com.stslex93.notes.core.notes.model.toEntity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.withContext
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class NoteRepositoryImpl @Inject constructor(
private val dao: NoteDao,
) : NoteRepository {
override fun getNoteFlow(id: Int): Flow<NoteDataModel> = dao.getNoteFlow(id = id)
.map { it.toData() }
.flowOn(Dispatchers.IO)
override suspend fun getNote(
id: Int
): NoteDataModel = withContext(Dispatchers.IO) {
dao.getNote(id).toData()
}
override fun searchNotes(
query: String
): Flow<PagingData<NoteDataModel>> =
Pager(
PagingConfig(
pageSize = PAGE_SIZE,
enablePlaceholders = IS_PLACEHOLDER_ENABLE
)
) {
dao.getAll(query)
}
.flow
.map { pagingData ->
pagingData.map { it.toData() }
}
.flowOn(Dispatchers.IO)
override suspend fun deleteNotesById(ids: List<Int>) {
withContext(Dispatchers.IO) {
dao.deleteNotesById(ids = ids)
}
}
override suspend fun insert(note: NoteDataModel) {
withContext(Dispatchers.IO) {
dao.insert(note = note.toEntity())
}
}
companion object {
private const val PAGE_SIZE = 15
private const val IS_PLACEHOLDER_ENABLE = false
}
}