diff --git a/lib/src/main/java/net/opatry/ticktick/TickTickService.kt b/lib/src/main/java/net/opatry/ticktick/TickTickService.kt index 8bd390d..32f721f 100644 --- a/lib/src/main/java/net/opatry/ticktick/TickTickService.kt +++ b/lib/src/main/java/net/opatry/ticktick/TickTickService.kt @@ -127,7 +127,25 @@ class HttpTickTickService(private val httpClient: HttpClient) : TickTickService } override suspend fun updateTask(taskId: String, request: TaskUpdateRequest): Task { - return httpClient.postOrThrow("open/v1/task/${taskId}", request) + require(taskId == request.id) { "Provided task id ($taskId) and update request id (${request.id}) doesn't match." } + // FIXME edge cases encountered + // if the project id provided in the task is invalid, we receive a 500 error from server + // if the project id doesn't match the updated task's one, we receive a 200 success without data (can't be used to move a task to another project) + // return httpClient.postOrThrow("open/v1/task/${taskId}", request) + val response = httpClient.post("open/v1/task/${taskId}") { + contentType(ContentType.Application.Json) + setBody(request) + } + + if (response.status.isSuccess()) { + if (response.bodyAsText().isNotEmpty()) { + return response.body() + } else { + throw ClientRequestException(response, "Task not updated (invalid project id? ${request.projectId})") + } + } else { + throw ClientRequestException(response, response.bodyAsText()) + } } override suspend fun completeTask(projectId: String, taskId: String) { diff --git a/lib/src/test/java/net/opatry/ticktick/service/TickTickServiceTaskTest.kt b/lib/src/test/java/net/opatry/ticktick/service/TickTickServiceTaskTest.kt index 8946f81..99ad705 100644 --- a/lib/src/test/java/net/opatry/ticktick/service/TickTickServiceTaskTest.kt +++ b/lib/src/test/java/net/opatry/ticktick/service/TickTickServiceTaskTest.kt @@ -310,7 +310,7 @@ class TickTickServiceTaskTest { runBlocking { ticktickService.updateTask( "6247ee29630c800f064fd145", - TaskUpdateRequest(projectId = "", id = "", content = "Bar") + TaskUpdateRequest(projectId = "6226ff9877acee87727f6bca", id = "6247ee29630c800f064fd145", content = "Bar") ) } }