Skip to content

Commit 2ef49bf

Browse files
committed
feat: support schemes and implement a router for it
1 parent 1159287 commit 2ef49bf

File tree

5 files changed

+162
-7
lines changed

5 files changed

+162
-7
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.ctrlhub.core.governance.response
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
5+
6+
@JsonIgnoreProperties(ignoreUnknown = true)
7+
class Label @JsonCreator constructor(
8+
var key: String = "",
9+
var value: String = ""
10+
) {
11+
constructor(): this(
12+
key = "",
13+
value = ""
14+
)
15+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.ctrlhub.core.governance.schemes
2+
3+
import com.ctrlhub.core.Api
4+
import com.ctrlhub.core.governance.schemes.response.Scheme
5+
import com.ctrlhub.core.governance.schemes.workorders.response.WorkOrder
6+
import com.ctrlhub.core.router.Router
7+
import com.ctrlhub.core.router.request.FilterOption
8+
import com.ctrlhub.core.router.request.JsonApiIncludes
9+
import com.ctrlhub.core.router.request.RequestParametersWithIncludes
10+
import io.ktor.client.HttpClient
11+
12+
enum class SchemeIncludes(val value: String): JsonApiIncludes {
13+
WorkOrders("work_orders"),
14+
WorkOrdersOperations("work_orders.operations");
15+
16+
override fun value(): String {
17+
return value
18+
}
19+
}
20+
21+
class SchemeRequestParameters(
22+
filterOptions: List<FilterOption> = emptyList(),
23+
includes: List<SchemeIncludes> = emptyList()
24+
) : RequestParametersWithIncludes<SchemeIncludes>(filterOptions, includes)
25+
26+
class SchemesRouter(httpClient: HttpClient) : Router(httpClient) {
27+
28+
/**
29+
* Retrieve a list of all schemes
30+
*
31+
* @param organisationId String The organisation ID to retrieve all equipment items for
32+
* @param requestParameters RequestParameters An instance of SchemeRequestParameters, capturing sorting, filtering and pagination based request params
33+
*
34+
* @return A list of all schemes
35+
*/
36+
suspend fun all(organisationId: String, requestParameters: SchemeRequestParameters = SchemeRequestParameters()): List<Scheme> {
37+
return fetchJsonApiResources("/v3/orgs/$organisationId/governance/schemes", requestParameters.toMap(), Scheme::class.java,
38+
WorkOrder::class.java)
39+
}
40+
41+
/**
42+
* Retrieve a single scheme item
43+
*
44+
* @param organisationId String The organisation ID to retrieve all equipment items for
45+
* @param schemeId String The scheme ID to retrieve data for
46+
* @param requestParameters RequestParameters An instance of SchemeRequestParameters, capturing sorting, filtering and pagination based request params
47+
*
48+
* @return A single scheme
49+
*/
50+
suspend fun one(organisationId: String, schemeId: String, requestParameters: SchemeRequestParameters = SchemeRequestParameters()) : Scheme {
51+
return fetchJsonApiResource("/v3/orgs/$organisationId/governance/schemes/$schemeId", requestParameters.toMap())
52+
}
53+
}
54+
55+
val Api.schemes: SchemesRouter
56+
get() = SchemesRouter(httpClient)
Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,78 @@
11
package com.ctrlhub.core.governance.schemes.response
22

3-
class Scheme {
4-
}
3+
import com.ctrlhub.core.governance.response.Label
4+
import com.ctrlhub.core.governance.schemes.workorders.response.WorkOrder
5+
import com.fasterxml.jackson.annotation.JsonCreator
6+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
7+
import com.fasterxml.jackson.annotation.JsonProperty
8+
import com.github.jasminb.jsonapi.StringIdHandler
9+
import com.github.jasminb.jsonapi.annotations.Id
10+
import com.github.jasminb.jsonapi.annotations.Meta
11+
import com.github.jasminb.jsonapi.annotations.Relationship
12+
import com.github.jasminb.jsonapi.annotations.Type
13+
import java.time.LocalDate
14+
15+
@Type("schemes")
16+
@JsonIgnoreProperties(ignoreUnknown = true)
17+
class Scheme @JsonCreator constructor(
18+
@Id(StringIdHandler::class) var id: String = "",
19+
@JsonProperty("name") var name: String = "",
20+
@JsonProperty("code") var code: String = "",
21+
@JsonProperty("start_date") var startDate: LocalDate? = null,
22+
@JsonProperty("end_date") var endDate: LocalDate? = null,
23+
24+
@JsonProperty("labels")
25+
var labels: List<Label> = emptyList(),
26+
27+
@Meta
28+
var meta: SchemeMeta? = null,
29+
30+
@Relationship("work_orders", resolve = true)
31+
var workOrders: List<WorkOrder> = emptyList(),
32+
) {
33+
constructor(): this(
34+
id = "",
35+
name = "",
36+
code = "",
37+
startDate = null,
38+
endDate = null,
39+
workOrders = emptyList()
40+
)
41+
}
42+
43+
@JsonIgnoreProperties(ignoreUnknown = true)
44+
class SchemeMeta @JsonCreator constructor(
45+
@JsonProperty("completeness") var completeness: SchemeCompleteness? = null,
46+
@JsonProperty("counts") var counts: SchemeCounts? = null,
47+
)
48+
49+
class SchemeCompleteness @JsonCreator constructor(
50+
@JsonProperty("counts") var counts: SchemeCompletenessCounts? = null,
51+
@JsonProperty("percentage") var percentage: SchemePercentages? = null
52+
) {
53+
constructor(): this(
54+
counts = null,
55+
percentage = null
56+
)
57+
}
58+
59+
class SchemeCompletenessCounts @JsonCreator constructor(
60+
var aborted: Int = 0,
61+
var cancelled: Int = 0,
62+
var completed: Int = 0,
63+
var unknown: Int = 0
64+
)
65+
66+
class SchemeCounts @JsonCreator constructor(
67+
var operations: Int = 0,
68+
var properties: Int = 0,
69+
var streets: Int = 0,
70+
@JsonProperty("work_orders") var workOrders: Int = 0
71+
)
72+
73+
class SchemePercentages @JsonCreator constructor(
74+
var aborted: Int = 0,
75+
var cancelled: Int = 0,
76+
var completed: Int = 0,
77+
var unknown: Int = 0
78+
)

src/main/kotlin/com/ctrlhub/core/governance/schemes/workorders/operations/response/Operation.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ import com.ctrlhub.core.iam.response.User
44
import com.fasterxml.jackson.annotation.JsonCreator
55
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
66
import com.fasterxml.jackson.annotation.JsonProperty
7+
import com.github.jasminb.jsonapi.StringIdHandler
8+
import com.github.jasminb.jsonapi.annotations.Id
79
import com.github.jasminb.jsonapi.annotations.Relationship
810
import com.github.jasminb.jsonapi.annotations.Type
911
import java.time.LocalDate
1012

1113
@Type("operations")
1214
@JsonIgnoreProperties(ignoreUnknown = true)
1315
class Operation @JsonCreator constructor(
16+
@Id(StringIdHandler::class) var id: String = "",
1417
@JsonProperty("name") var name: String = "",
1518
@JsonProperty("code") var code: String = "",
16-
@JsonProperty("description") var description: String = "",
19+
@JsonProperty("description") var description: String? = "",
1720
@JsonProperty("start_date") var startDate: LocalDate? = null,
1821
@JsonProperty("end_date") var endDate: LocalDate? = null,
19-
@JsonProperty("uprns") var uprns: List<String> = emptyList(),
20-
@JsonProperty("usrns") var usrns: List<String> = emptyList(),
22+
@JsonProperty("uprns") var uprns: List<String>? = emptyList(),
23+
@JsonProperty("usrns") var usrns: List<String>? = emptyList(),
2124
@JsonProperty("completed") var completed: Boolean = false,
2225
@JsonProperty("aborted") var aborted: Boolean = false,
2326
@JsonProperty("cancelled") var cancelled: Boolean = false,

src/main/kotlin/com/ctrlhub/core/governance/schemes/workorders/response/WorkOrder.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
package com.ctrlhub.core.governance.schemes.workorders.response
22

3+
import com.ctrlhub.core.governance.response.Label
34
import com.ctrlhub.core.governance.schemes.workorders.operations.response.Operation
45
import com.fasterxml.jackson.annotation.JsonCreator
56
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
67
import com.fasterxml.jackson.annotation.JsonProperty
8+
import com.github.jasminb.jsonapi.StringIdHandler
9+
import com.github.jasminb.jsonapi.annotations.Id
710
import com.github.jasminb.jsonapi.annotations.Relationship
811
import com.github.jasminb.jsonapi.annotations.Type
912
import java.time.LocalDate
1013

1114
@Type("work-orders")
1215
@JsonIgnoreProperties(ignoreUnknown = true)
1316
class WorkOrder @JsonCreator constructor(
17+
@Id(StringIdHandler::class) var id: String = "",
1418
@JsonProperty("name") var name: String = "",
1519
@JsonProperty("code") var code: String = "",
16-
@JsonProperty("description") var description: String = "",
20+
@JsonProperty("description") var description: String? = null,
1721
@JsonProperty("start_date") var startDate: LocalDate? = null,
1822
@JsonProperty("end_date") var endDate: LocalDate? = null,
1923

20-
@Relationship("operations")
24+
@JsonProperty("labels")
25+
var labels: List<Label> = emptyList(),
26+
27+
@Relationship("operations", resolve = true)
2128
var operations: List<Operation> = emptyList()
2229
) {
2330
constructor() : this(

0 commit comments

Comments
 (0)