@@ -3,12 +3,16 @@ package com.ctrlhub.core.datacapture
3
3
import com.ctrlhub.core.Api
4
4
import com.ctrlhub.core.api.response.PaginatedList
5
5
import com.ctrlhub.core.datacapture.response.FormSchema
6
+ import com.ctrlhub.core.datacapture.response.FormSchemaMeta
6
7
import com.ctrlhub.core.extractPaginationFromMeta
7
8
import com.ctrlhub.core.router.Router
8
9
import com.ctrlhub.core.router.request.RequestParameters
9
10
import io.ktor.client.HttpClient
10
11
import io.ktor.client.call.body
11
12
import kotlinx.serialization.json.*
13
+ import java.time.LocalDateTime
14
+ import java.time.ZonedDateTime
15
+ import java.time.format.DateTimeFormatter
12
16
13
17
class FormSchemasRouter (httpClient : HttpClient ) : Router(httpClient) {
14
18
@@ -53,10 +57,26 @@ class FormSchemasRouter(httpClient: HttpClient) : Router(httpClient) {
53
57
? : throw IllegalStateException (" Missing id" )
54
58
55
59
val rawContent = json.toString()
60
+ val isoFormatter = DateTimeFormatter .ISO_OFFSET_DATE_TIME
61
+
62
+ val formSchemaMeta = json[" meta" ]?.jsonObject?.let {
63
+ val createdAtStr = it[" created_at" ]?.jsonPrimitive?.content
64
+ val updatedAtStr = it[" updated_at" ]?.jsonPrimitive?.contentOrNull
65
+
66
+ FormSchemaMeta (
67
+ createdAt = createdAtStr?.let { ZonedDateTime .parse(it, isoFormatter).toLocalDateTime() }
68
+ ? : throw IllegalStateException (" Missing created_at" ),
69
+ updatedAt = updatedAtStr?.takeIf { it.isNotEmpty() }?.let {
70
+ ZonedDateTime .parse(it, isoFormatter).toLocalDateTime()
71
+ },
72
+ latest = it[" latest" ]?.jsonPrimitive?.content.orEmpty()
73
+ )
74
+ }
56
75
57
76
return FormSchema (
58
77
id = id,
59
- rawSchema = rawContent
78
+ rawSchema = rawContent,
79
+ meta = formSchemaMeta,
60
80
)
61
81
}
62
82
0 commit comments