Skip to content

Commit bdc505d

Browse files
committed
Handle new latest form schema meta changes
1 parent 4b1a056 commit bdc505d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/main/kotlin/com/ctrlhub/core/datacapture/FormSchemasRouter.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.ctrlhub.core.datacapture
33
import com.ctrlhub.core.Api
44
import com.ctrlhub.core.api.response.PaginatedList
55
import com.ctrlhub.core.datacapture.response.FormSchema
6+
import com.ctrlhub.core.datacapture.response.FormSchemaLatestMeta
67
import com.ctrlhub.core.datacapture.response.FormSchemaMeta
78
import com.ctrlhub.core.extractPaginationFromMeta
89
import com.ctrlhub.core.router.Router
@@ -59,7 +60,7 @@ class FormSchemasRouter(httpClient: HttpClient) : Router(httpClient) {
5960
val rawContent = json.toString()
6061
val isoFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME
6162

62-
val formSchemaMeta = json["meta"]?.jsonObject?.let {
63+
val formSchemaMeta = json["meta"]?.jsonObject?.let { it ->
6364
val createdAtStr = it["created_at"]?.jsonPrimitive?.content
6465
val updatedAtStr = it["updated_at"]?.jsonPrimitive?.contentOrNull
6566

@@ -69,7 +70,12 @@ class FormSchemasRouter(httpClient: HttpClient) : Router(httpClient) {
6970
updatedAt = updatedAtStr?.takeIf { it.isNotEmpty() }?.let {
7071
ZonedDateTime.parse(it, isoFormatter).toLocalDateTime()
7172
},
72-
latest = it["latest"]?.jsonPrimitive?.content.orEmpty()
73+
latest = it["latest"]?.let { latestJson ->
74+
FormSchemaLatestMeta(
75+
id = latestJson.jsonObject["id"]?.jsonPrimitive?.content ?: "",
76+
version = latestJson.jsonObject["version"]?.jsonPrimitive?.content ?: "",
77+
)
78+
}
7379
)
7480
}
7581

src/main/kotlin/com/ctrlhub/core/datacapture/response/FormSchema.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,11 @@ data class FormSchema(
2323
data class FormSchemaMeta @JsonCreator constructor(
2424
@JsonProperty("created_at") var createdAt: LocalDateTime,
2525
@JsonProperty("updated_at") var updatedAt: LocalDateTime?,
26-
@JsonProperty("latest") var latest: String,
26+
@JsonProperty("latest") var latest: FormSchemaLatestMeta? = null,
27+
)
28+
29+
@JsonIgnoreProperties(ignoreUnknown = true)
30+
data class FormSchemaLatestMeta(
31+
@JsonProperty("id") val id: String = "",
32+
@JsonProperty("version") val version: String = "",
2733
)

0 commit comments

Comments
 (0)