added Properties to created Tasks
This commit is contained in:
1 parent
99a494608f
commit
8078e34a2c
10 files changed
+792
-51
No files matched your search
@@ -2,10 +2,12 @@ package ch.ergon.anytask.api.dto
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
|
||||
@Serializable
|
||||
data class CreateObjectRequest(
|
||||
val name: String,
|
||||
val body: String,
|
||||
@SerialName("type_key") val typeKey: String,
|
||||
)
|
||||
val properties: List<JsonElement> = emptyList(),
|
||||
)
|
||||
@@ -0,0 +1,34 @@
|
||||
package ch.ergon.anytask.api.dto
|
||||
|
||||
import kotlinx.serialization.json.JsonArray
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
|
||||
fun buildPropertyValue(key: String, format: String, value: String): JsonElement? {
|
||||
if (value.isBlank()) return null
|
||||
|
||||
return when (format) {
|
||||
"text" -> JsonObject(mapOf("key" to JsonPrimitive(key), "text" to JsonPrimitive(value)))
|
||||
"number" -> JsonObject(mapOf("key" to JsonPrimitive(key), "number" to JsonPrimitive(value.toDoubleOrNull() ?: 0.0)))
|
||||
"select" -> JsonObject(mapOf("key" to JsonPrimitive(key), "select" to JsonPrimitive(value)))
|
||||
"multi_select" -> {
|
||||
val items = value.split(",").map { it.trim() }.filter { it.isNotEmpty() }
|
||||
JsonObject(mapOf("key" to JsonPrimitive(key), "multi_select" to JsonArray(items.map { JsonPrimitive(it) })))
|
||||
}
|
||||
"date" -> JsonObject(mapOf("key" to JsonPrimitive(key), "date" to JsonPrimitive(value)))
|
||||
"checkbox" -> JsonObject(mapOf("key" to JsonPrimitive(key), "checkbox" to JsonPrimitive(value.toBooleanStrictOrNull() ?: false)))
|
||||
"url" -> JsonObject(mapOf("key" to JsonPrimitive(key), "url" to JsonPrimitive(value)))
|
||||
"email" -> JsonObject(mapOf("key" to JsonPrimitive(key), "email" to JsonPrimitive(value)))
|
||||
"phone" -> JsonObject(mapOf("key" to JsonPrimitive(key), "phone" to JsonPrimitive(value)))
|
||||
"files" -> {
|
||||
val ids = value.split(",").map { it.trim() }.filter { it.isNotEmpty() }
|
||||
JsonObject(mapOf("key" to JsonPrimitive(key), "files" to JsonArray(ids.map { JsonPrimitive(it) })))
|
||||
}
|
||||
"object", "objects" -> {
|
||||
val ids = value.split(",").map { it.trim() }.filter { it.isNotEmpty() }
|
||||
JsonObject(mapOf("key" to JsonPrimitive(key), "objects" to JsonArray(ids.map { JsonPrimitive(it) })))
|
||||
}
|
||||
else -> JsonObject(mapOf("key" to JsonPrimitive(key), "text" to JsonPrimitive(value)))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package ch.ergon.anytask.api.dto
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class SearchObject(
|
||||
val id: String,
|
||||
val name: String,
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
package ch.ergon.anytask.api.dto
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class SearchObjectsResponse(
|
||||
val data: List<SearchObject>,
|
||||
)
|
||||