diff --git a/google/tasks/src/commonMain/kotlin/net/opatry/google/tasks/TaskListsApi.kt b/google/tasks/src/commonMain/kotlin/net/opatry/google/tasks/TaskListsApi.kt index 695d03cd..dbfd8843 100644 --- a/google/tasks/src/commonMain/kotlin/net/opatry/google/tasks/TaskListsApi.kt +++ b/google/tasks/src/commonMain/kotlin/net/opatry/google/tasks/TaskListsApi.kt @@ -119,22 +119,6 @@ class TaskListsApi( } } - /** - * Iterate on [list]'s paginated results and returns single list of all task lists. - * - * @see [list] - */ - suspend fun listAll(): List { - var nextPageToken: String? = null - return buildList { - do { - val response = list(maxResults = 100, nextPageToken) - addAll(response.items) - nextPageToken = response.nextPageToken - } while (nextPageToken != null) - } - } - /** * [Updates the authenticated user's specified task list](https://developers.google.com/tasks/reference/rest/v1/tasklists/patch). This method supports patch semantics. * @@ -176,4 +160,20 @@ class TaskListsApi( throw ClientRequestException(response, response.bodyAsText()) } } -} \ No newline at end of file +} + +/** + * Iterate on [TaskListsApi.list]'s paginated results and returns single list of all task lists. + * + * @see [TaskListsApi.list] + */ +suspend fun TaskListsApi.listAll(): List { + var nextPageToken: String? = null + return buildList { + do { + val response = list(maxResults = 100, nextPageToken) + addAll(response.items) + nextPageToken = response.nextPageToken + } while (nextPageToken != null) + } +} diff --git a/google/tasks/src/commonMain/kotlin/net/opatry/google/tasks/TasksApi.kt b/google/tasks/src/commonMain/kotlin/net/opatry/google/tasks/TasksApi.kt index 6371c66a..180bac85 100644 --- a/google/tasks/src/commonMain/kotlin/net/opatry/google/tasks/TasksApi.kt +++ b/google/tasks/src/commonMain/kotlin/net/opatry/google/tasks/TasksApi.kt @@ -191,46 +191,6 @@ class TasksApi( } } - /** - * Iterate on [list]'s paginated results and returns single list of all tasks. - * - * @see [list] - */ - suspend fun listAll( - taskListId: String, - completedMin: Instant? = null, - completedMax: Instant? = null, - dueMin: Instant? = null, - dueMax: Instant? = null, - showCompleted: Boolean = true, - showDeleted: Boolean = false, - showHidden: Boolean = false, - updatedMin: Instant? = null, - showAssigned: Boolean = false - ): List { - var nextPageToken: String? = null - return buildList { - do { - val response = list( - taskListId, - completedMin, - completedMax, - dueMin, - dueMax, - maxResults = 100, - nextPageToken, - showCompleted, - showDeleted, - showHidden, - updatedMin, - showAssigned - ) - addAll(response.items) - nextPageToken = response.nextPageToken - } while (nextPageToken != null) - } - } - /** * [Moves the specified task](https://developers.google.com/tasks/reference/rest/v1/tasks/move) to another position in the destination task list. * @@ -306,4 +266,44 @@ class TasksApi( throw ClientRequestException(response, response.bodyAsText()) } } -} \ No newline at end of file +} + +/** + * Iterate on [TasksApi.list]'s paginated results and returns single list of all tasks. + * + * @see [TasksApi.list] + */ +suspend fun TasksApi.listAll( + taskListId: String, + completedMin: Instant? = null, + completedMax: Instant? = null, + dueMin: Instant? = null, + dueMax: Instant? = null, + showCompleted: Boolean = true, + showDeleted: Boolean = false, + showHidden: Boolean = false, + updatedMin: Instant? = null, + showAssigned: Boolean = false +): List { + var nextPageToken: String? = null + return buildList { + do { + val response = list( + taskListId, + completedMin, + completedMax, + dueMin, + dueMax, + maxResults = 100, + nextPageToken, + showCompleted, + showDeleted, + showHidden, + updatedMin, + showAssigned + ) + addAll(response.items) + nextPageToken = response.nextPageToken + } while (nextPageToken != null) + } +} diff --git a/tasks-core/src/commonMain/kotlin/net/opatry/tasks/data/TaskRepository.kt b/tasks-core/src/commonMain/kotlin/net/opatry/tasks/data/TaskRepository.kt index 493a61a1..aad70b58 100644 --- a/tasks-core/src/commonMain/kotlin/net/opatry/tasks/data/TaskRepository.kt +++ b/tasks-core/src/commonMain/kotlin/net/opatry/tasks/data/TaskRepository.kt @@ -34,6 +34,7 @@ import kotlinx.datetime.Clock import kotlinx.datetime.Instant import net.opatry.google.tasks.TaskListsApi import net.opatry.google.tasks.TasksApi +import net.opatry.google.tasks.listAll import net.opatry.google.tasks.model.Task import net.opatry.google.tasks.model.TaskList import net.opatry.tasks.data.entity.TaskEntity