From d74e243cf79a4fdd81304c582cc87f11e6d6edf2 Mon Sep 17 00:00:00 2001 From: boxi Date: Fri, 15 May 2026 20:39:49 +0200 Subject: [PATCH] fixed API --- httpClient/anyType.http | 25 +++++++++++++------ .../kotlin/ch/ergon/anytask/api/AnyTypeApi.kt | 16 ++++++------ .../anytask/api/dto/CreateObjectRequest.kt | 2 +- .../kotlin/ch/ergon/anytask/api/dto/Tag.kt | 11 ++++++++ .../ch/ergon/anytask/api/dto/TagsResponse.kt | 8 ++++++ 5 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 src/main/kotlin/ch/ergon/anytask/api/dto/Tag.kt create mode 100644 src/main/kotlin/ch/ergon/anytask/api/dto/TagsResponse.kt diff --git a/httpClient/anyType.http b/httpClient/anyType.http index c9e9da3..a0c8e45 100644 --- a/httpClient/anyType.http +++ b/httpClient/anyType.http @@ -1,21 +1,22 @@ ### Get Spaces GET http://localhost:31009/v1/spaces Authorization: Bearer {{apiKey}} +Anytype-Version: 2025-11-08 ### Get Types GET http://localhost:31009/v1/spaces/{{spaceId}}/types Authorization: Bearer {{apiKey}} -Anytype-Version: 0.1 +Anytype-Version: 2025-11-08 ### Get Type GET http://localhost:31009/v1/spaces/{{spaceId}}/types/{{taskTypeId}} Authorization: Bearer {{apiKey}} -Anytype-Version: 0.1 +Anytype-Version: 2025-11-08 ### Get objects of type POST http://localhost:31009/v1/spaces/{{spaceId}}/search?type=project Authorization: Bearer {{apiKey}} -Anytype-Version: 0.1 +Anytype-Version: 2025-11-08 Content-Type: application/json { @@ -23,19 +24,29 @@ Content-Type: application/json } ### Get Property -GET http://localhost:31009/v1/spaces/{{spaceId}}/properties/{{priorityPropertyId}} +GET http://localhost:31009/v1/spaces/{{spaceId}}/properties/{{priorityPropertyId}}/tags Authorization: Bearer {{apiKey}} -Anytype-Version: 0.1 +Anytype-Version: 2025-11-08 + +### Get Property Values Priority +GET http://localhost:31009/v1/spaces/{{spaceId}}/properties/{{priorityPropertyId}}/tags +Authorization: Bearer {{apiKey}} +Anytype-Version: 2025-11-08 + +### Get Property Values Project +GET http://localhost:31009/v1/spaces/{{spaceId}}/properties/{{projectPropertyId}}/tags +Authorization: Bearer {{apiKey}} +Anytype-Version: 2025-11-08 ### Get Property Tags GET http://localhost:31009/v1/spaces/{{spaceId}}/properties/{{priorityPropertyId}}/tags Authorization: Bearer {{apiKey}} -Anytype-Version: 0.1 +Anytype-Version: 2025-11-08 ### Get Templates GET http://localhost:31009/v1/spaces/{{spaceId}}/types/{{taskTypeId}}/templates Authorization: Bearer {{apiKey}} -Anytype-Version: 0.1 +Anytype-Version: 2025-11-08 ### Create Task POST http://localhost:31009/v1/spaces/{{spaceId}}/objects diff --git a/src/main/kotlin/ch/ergon/anytask/api/AnyTypeApi.kt b/src/main/kotlin/ch/ergon/anytask/api/AnyTypeApi.kt index 8f531bd..5c28d6d 100644 --- a/src/main/kotlin/ch/ergon/anytask/api/AnyTypeApi.kt +++ b/src/main/kotlin/ch/ergon/anytask/api/AnyTypeApi.kt @@ -6,6 +6,7 @@ import io.ktor.client.call.* import io.ktor.client.engine.cio.* import io.ktor.client.plugins.* import io.ktor.client.plugins.contentnegotiation.* +import io.ktor.client.plugins.defaultRequest import io.ktor.client.request.* import io.ktor.client.statement.* import io.ktor.http.* @@ -32,7 +33,10 @@ class AnyTypeApi( private val http = HttpClient(CIO) { install(ContentNegotiation) { - json(Json { ignoreUnknownKeys = true }) + json(Json { ignoreUnknownKeys = true; explicitNulls = false }) + } + defaultRequest { + header("Anytype-Version", "2025-11-08") } }.also { client -> client.plugin(HttpSend).intercept { request -> @@ -62,7 +66,6 @@ class AnyTypeApi( suspend fun getSpaces(): Result> = runCatching { val response = http.get("$baseUrl/v1/spaces") { - header("Anytype-Version", "0.1") bearerAuth(apiKey) } response.body().data @@ -71,7 +74,6 @@ class AnyTypeApi( suspend fun getTypes(): Result> = runCatching { val response = http.get("$baseUrl/v1/spaces/$spaceId/types") { - header("Anytype-Version", "0.1") bearerAuth(apiKey) } response.body().data @@ -81,7 +83,6 @@ class AnyTypeApi( runCatching { val response = http.post("$baseUrl/v1/spaces/$spaceId/search") { contentType(ContentType.Application.Json) - header("Anytype-Version", "0.1") bearerAuth(apiKey) setBody(mapOf("types" to listOf(typeKey))) } @@ -91,7 +92,6 @@ class AnyTypeApi( suspend fun getTags(propertyId: String): Result> = runCatching { val response = http.get("$baseUrl/v1/spaces/$spaceId/properties/$propertyId/tags") { - header("Anytype-Version", "2025-11-08") bearerAuth(apiKey) } response.body().data @@ -100,7 +100,6 @@ class AnyTypeApi( suspend fun getTemplates(typeId: String): Result> = runCatching { val response = http.get("$baseUrl/v1/spaces/$spaceId/types/$typeId/templates") { - header("Anytype-Version", "0.1") bearerAuth(apiKey) } response.body().data @@ -108,7 +107,7 @@ class AnyTypeApi( suspend fun createObject( title: String, - details: String = "", + details: String? = null, typeKey: String, templateId: String? = null, properties: List = emptyList(), @@ -116,12 +115,11 @@ class AnyTypeApi( runCatching { val response = http.post("$baseUrl/v1/spaces/$spaceId/objects") { contentType(ContentType.Application.Json) - header("Anytype-Version", "0.1") bearerAuth(apiKey) setBody( CreateObjectRequest( name = title, - body = details, + body = details?.takeIf { it.isNotBlank() }, typeKey = typeKey, templateId = templateId, properties = properties, diff --git a/src/main/kotlin/ch/ergon/anytask/api/dto/CreateObjectRequest.kt b/src/main/kotlin/ch/ergon/anytask/api/dto/CreateObjectRequest.kt index aee1d3f..33ed65e 100644 --- a/src/main/kotlin/ch/ergon/anytask/api/dto/CreateObjectRequest.kt +++ b/src/main/kotlin/ch/ergon/anytask/api/dto/CreateObjectRequest.kt @@ -7,7 +7,7 @@ import kotlinx.serialization.json.JsonElement @Serializable data class CreateObjectRequest( val name: String, - val body: String, + val body: String? = null, @SerialName("type_key") val typeKey: String, @SerialName("template_id") val templateId: String? = null, val properties: List = emptyList(), diff --git a/src/main/kotlin/ch/ergon/anytask/api/dto/Tag.kt b/src/main/kotlin/ch/ergon/anytask/api/dto/Tag.kt new file mode 100644 index 0000000..cff0bbe --- /dev/null +++ b/src/main/kotlin/ch/ergon/anytask/api/dto/Tag.kt @@ -0,0 +1,11 @@ +package ch.ergon.anytask.api.dto + +import kotlinx.serialization.Serializable + +@Serializable +data class Tag( + val id: String, + val key: String = "", + val name: String, + val color: String = "", +) diff --git a/src/main/kotlin/ch/ergon/anytask/api/dto/TagsResponse.kt b/src/main/kotlin/ch/ergon/anytask/api/dto/TagsResponse.kt new file mode 100644 index 0000000..415804a --- /dev/null +++ b/src/main/kotlin/ch/ergon/anytask/api/dto/TagsResponse.kt @@ -0,0 +1,8 @@ +package ch.ergon.anytask.api.dto + +import kotlinx.serialization.Serializable + +@Serializable +data class TagsResponse( + val data: List, +)