-
-
Save aleweichandt/bbda3111facfe1f1a12f0aff13df5d25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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