Skip to content

Instantly share code, notes, and snippets.

@aleweichandt
Created Aug 16, 2021
Embed
What would you like to do?
class TodosCache(
private val dao: TodoDao,
exceptionHandler: IExceptionHandler
) : Cache(exceptionHandler), ITodoCache {
companion object {
private const val tag = "LOCAL-SOURCE"
}
override suspend fun getAllTodos() =
runQuery { dao.getAll().map { it.toDomain() } }
override suspend fun getTodoById(id: Long) =
runQuery { dao.getById(id)?.toDomain() }
override suspend fun storeAllTodos(todos: List<Todo>) {
runQuery {
todos
.map(Todo::toEntity)
.let { dao.replaceAll(*it.toTypedArray()) }
}
}
override suspend fun storeTodo(todo: Todo) {
runQuery { dao.insert(todo.toEntity()) }
}
override suspend fun deleteAllTodos() {
runQuery { dao.deleteAll() }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment