diff --git a/httpClient/anyType.http b/httpClient/anyType.http index 9a62334..835a532 100644 --- a/httpClient/anyType.http +++ b/httpClient/anyType.http @@ -27,13 +27,19 @@ GET http://localhost:31009/v1/spaces/{{spaceId}}/properties/{{priorityPropertyId Authorization: Bearer {{apiKey}} Anytype-Version: 0.1 +### Get Templates +GET http://localhost:31009/v1/spaces/{{spaceId}}/types/{{taskTypeId}}/templates +Authorization: Bearer {{apiKey}} +Anytype-Version: 0.1 + ### Create Task POST http://localhost:31009/v1/spaces/{{spaceId}}/objects Authorization: Bearer {{apiKey}} Content-Type: application/json { - "name": "Test Task II", - "body": "Created via HTTP client", + "name": "With Template - II", + "body": "And here comes the body", + "template_id": "bafyreidivup2xrqn4xbgimukkgst3ao24izqnpxdesbkdtnc5owvhf6i6i", "type_key": "ot-task" } diff --git a/src/main/kotlin/ch/ergon/anytask/api/AnyTypeApi.kt b/src/main/kotlin/ch/ergon/anytask/api/AnyTypeApi.kt index 9aee4ce..432a176 100644 --- a/src/main/kotlin/ch/ergon/anytask/api/AnyTypeApi.kt +++ b/src/main/kotlin/ch/ergon/anytask/api/AnyTypeApi.kt @@ -88,10 +88,20 @@ class AnyTypeApi( response.body().data } + 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 + } + suspend fun createObject( title: String, details: String = "", typeKey: String, + templateId: String? = null, properties: List = emptyList(), ): Result = runCatching { @@ -104,6 +114,7 @@ class AnyTypeApi( name = title, body = details, 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 0b78aaa..aee1d3f 100644 --- a/src/main/kotlin/ch/ergon/anytask/api/dto/CreateObjectRequest.kt +++ b/src/main/kotlin/ch/ergon/anytask/api/dto/CreateObjectRequest.kt @@ -9,5 +9,6 @@ data class CreateObjectRequest( val name: String, val body: String, @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/Template.kt b/src/main/kotlin/ch/ergon/anytask/api/dto/Template.kt new file mode 100644 index 0000000..b22855d --- /dev/null +++ b/src/main/kotlin/ch/ergon/anytask/api/dto/Template.kt @@ -0,0 +1,18 @@ +package ch.ergon.anytask.api.dto + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class Template( + val id: String, + val name: String, + val archived: Boolean = false, + val icon: Icon? = null, + val layout: String = "", + val `object`: String = "", + val properties: List = emptyList(), + val snippet: String = "", + @SerialName("space_id") val spaceId: String = "", + val type: ObjectType? = null, +) \ No newline at end of file diff --git a/src/main/kotlin/ch/ergon/anytask/api/dto/TemplatesResponse.kt b/src/main/kotlin/ch/ergon/anytask/api/dto/TemplatesResponse.kt new file mode 100644 index 0000000..ca1f3d7 --- /dev/null +++ b/src/main/kotlin/ch/ergon/anytask/api/dto/TemplatesResponse.kt @@ -0,0 +1,8 @@ +package ch.ergon.anytask.api.dto + +import kotlinx.serialization.Serializable + +@Serializable +data class TemplatesResponse( + val data: List