filter selected tasks for v1 and v2

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-12-13 10:44:43 +01:00 committed by Alper Öztürk
parent 98cd991502
commit edd42aabd1
5 changed files with 25 additions and 31 deletions

View file

@ -46,7 +46,7 @@ class AssistantRepositoryTests : AbstractOnServerIT() {
}
val result = sut?.getTaskList("assistant")
assertTrue(result?.tasks?.isEmpty() == true || (result?.tasks?.size ?: 0) > 0)
assertTrue(result?.isEmpty() == true || (result?.size ?: 0) > 0)
}
@Test
@ -81,13 +81,11 @@ class AssistantRepositoryTests : AbstractOnServerIT() {
sleep(120)
val resultOfTaskList = sut?.getTaskList("assistant")
assertTrue(resultOfTaskList != null)
val taskList = sut?.getTaskList("assistant")
assertTrue(taskList != null)
sleep(120)
val taskList = resultOfTaskList?.tasks
assert((taskList?.size ?: 0) > 0)
val result = sut?.deleteTask(taskList!!.first().id)

View file

@ -102,7 +102,7 @@ class AssistantViewModel(
val taskType = _selectedTaskType.value?.id ?: return@launch
val result = repository.getTaskList(taskType)
if (result != null) {
taskList = result.tasks.filter { it.appId == "assistant" }
taskList = result
_filteredTaskList.update {
taskList?.sortedByDescending { task ->
task.id

View file

@ -12,7 +12,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.resources.assistant.v2.model.Task
import com.owncloud.android.lib.resources.assistant.v2.model.TaskInput
import com.owncloud.android.lib.resources.assistant.v2.model.TaskInputShape
import com.owncloud.android.lib.resources.assistant.v2.model.TaskList
import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutput
import com.owncloud.android.lib.resources.assistant.v2.model.TaskOutputShape
import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData
@ -47,11 +46,10 @@ class AssistantMockRepository(private val giveEmptyTasks: Boolean = false) : Ass
return RemoteOperationResult<Void>(RemoteOperationResult.ResultCode.OK)
}
override fun getTaskList(taskType: String): TaskList {
override fun getTaskList(taskType: String): List<Task> {
return if (giveEmptyTasks) {
TaskList(listOf())
listOf()
} else {
TaskList(
listOf(
Task(
1,
@ -68,7 +66,6 @@ class AssistantMockRepository(private val giveEmptyTasks: Boolean = false) : Ass
1707692337
)
)
)
}
}

View file

@ -19,7 +19,7 @@ import com.owncloud.android.lib.resources.assistant.v2.CreateTaskRemoteOperation
import com.owncloud.android.lib.resources.assistant.v2.DeleteTaskRemoteOperationV2
import com.owncloud.android.lib.resources.assistant.v2.GetTaskListRemoteOperationV2
import com.owncloud.android.lib.resources.assistant.v2.GetTaskTypesRemoteOperationV2
import com.owncloud.android.lib.resources.assistant.v2.model.TaskList
import com.owncloud.android.lib.resources.assistant.v2.model.Task
import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData
import com.owncloud.android.lib.resources.status.NextcloudVersion
import com.owncloud.android.lib.resources.status.OCCapability
@ -58,16 +58,16 @@ class AssistantRepository(private val client: NextcloudClient, capability: OCCap
}
@Suppress("ReturnCount")
override fun getTaskList(taskType: String): TaskList? {
override fun getTaskList(taskType: String): List<Task>? {
if (supportsV2) {
val result = GetTaskListRemoteOperationV2(taskType).execute(client)
if (result.isSuccess) {
return result.resultData
return result.resultData.tasks.filter { it.appId == "assistant" }
}
} else {
val result = GetTaskListRemoteOperationV1("assistant").execute(client)
if (result.isSuccess) {
return result.resultData.toV2()
return result.resultData.toV2().tasks.filter { it.type == taskType }
}
}

View file

@ -8,7 +8,6 @@
package com.nextcloud.client.assistant.repository
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.resources.assistant.v2.model.TaskList
import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData
interface AssistantRepositoryType {
@ -16,7 +15,7 @@ interface AssistantRepositoryType {
fun createTask(input: String, taskType: TaskTypeData): RemoteOperationResult<Void>
fun getTaskList(taskType: String): TaskList?
fun getTaskList(taskType: String): List<com.owncloud.android.lib.resources.assistant.v2.model.Task>?
fun deleteTask(id: Long): RemoteOperationResult<Void>
}