Skip to content

Commit 6cebc3c

Browse files
committed
feat: define a form schema resource type and a router to retrieve resources for it
1 parent 62157d7 commit 6cebc3c

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.ctrlhub.core.datacapture
2+
3+
import com.ctrlhub.core.api.response.PaginatedList
4+
import com.ctrlhub.core.datacapture.response.FormSchema
5+
import com.ctrlhub.core.router.Router
6+
import com.ctrlhub.core.router.request.RequestParameters
7+
import io.ktor.client.HttpClient
8+
9+
/**
10+
* A router that interacts with the form schemas realm of the Ctrl Hub API
11+
*/
12+
class FormSchemasRouter(httpClient: HttpClient): Router(httpClient) {
13+
14+
/**
15+
* Get all form schemas for a given form and organisation
16+
*
17+
* @param organisationId String The organisation ID to retrieve all for schemas for
18+
* @param formId String The form ID to retrieve all schemas for
19+
*
20+
* @return A paginated response of all form schemas
21+
*/
22+
suspend fun all(organisationId: String, formId: String, requestParameters: RequestParameters = RequestParameters()): PaginatedList<FormSchema> {
23+
val endpoint = "/v3/orgs/${organisationId}/data-capture/forms/{$formId}/schemas"
24+
25+
return fetchPaginatedJsonApiResources(endpoint, requestParameters.toMap(), FormSchema::class.java)
26+
}
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.ctrlhub.core.datacapture.response
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator
4+
import com.fasterxml.jackson.annotation.JsonProperty
5+
import com.fasterxml.jackson.databind.JsonNode
6+
import com.github.jasminb.jsonapi.annotations.Type
7+
8+
@Type("")
9+
data class FormSchema @JsonCreator constructor(
10+
val id: String,
11+
12+
@JsonProperty("model")
13+
private val modelNode: JsonNode,
14+
15+
@JsonProperty("views")
16+
private val viewsNode: JsonNode?
17+
) {
18+
val model: String = modelNode.toString()
19+
val views: String? = viewsNode?.toString()
20+
}

0 commit comments

Comments
 (0)