Skip to content

Commit e070e13

Browse files
authoredMay 2, 2024
Sorted imageMetaData from new to old (#407)
* Sorted imageMetaData from new to old * Updated openApi spec
1 parent d77c78a commit e070e13

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed
 

‎openapi.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ paths:
120120
get:
121121
tags:
122122
- persons
123-
summary: Returns metadata of images associated with a person.
123+
summary: Returns metadata of images associated with a person ordered by newest to oldest date.
124124
parameters:
125125
- $ref: "#/components/parameters/HmppsId"
126126
- $ref: "#/components/parameters/Page"

‎src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/NomisGateway.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class NomisGateway(
4949

5050
return when (result) {
5151
is WebClientWrapperResponse.Success -> {
52-
Response(data = result.data.map { it.toImageMetadata() })
52+
Response(data = result.data.map { it.toImageMetadata() }.sortedByDescending { it.captureDateTime })
5353
}
5454

5555
is WebClientWrapperResponse.Error -> {

‎src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetImageMetadataForPersonService.kt

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ class GetImageMetadataForPersonService(
1414
) {
1515
fun execute(hmppsId: String): Response<List<ImageMetadata>> {
1616
val responseFromProbationOffenderSearch = probationOffenderSearchGateway.getPerson(hmppsId)
17-
val nomisNumber = responseFromProbationOffenderSearch.data?.identifiers?.nomisNumber
18-
19-
if (nomisNumber == null) {
20-
return Response(
17+
val nomisNumber =
18+
responseFromProbationOffenderSearch.data?.identifiers?.nomisNumber ?: return Response(
2119
data = emptyList(),
2220
errors = responseFromProbationOffenderSearch.errors,
2321
)
24-
}
2522

2623
return nomisGateway.getImageMetadataForPerson(nomisNumber)
2724
}

‎src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/nomis/GetImageMetadataForPersonTest.kt

+28-5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ class GetImageMetadataForPersonTest(
4747
"imageView": "FACE",
4848
"imageOrientation": "FRONT",
4949
"imageType": "OFF_BKG"
50+
},
51+
{
52+
"imageId": 24299,
53+
"active": true,
54+
"captureDateTime": "2010-08-27T16:35:00",
55+
"imageView": "FACE",
56+
"imageOrientation": "FRONT",
57+
"imageType": "OFF_BKG"
5058
}
5159
]
5260
""",
@@ -69,11 +77,26 @@ class GetImageMetadataForPersonTest(
6977
it("returns image metadata for the matching person ID") {
7078
val response = nomisGateway.getImageMetadataForPerson(offenderNo)
7179

72-
response.data.first().active.shouldBe(true)
73-
response.data.first().captureDateTime.shouldBe(LocalDateTime.parse("2008-08-27T16:35:00"))
74-
response.data.first().view.shouldBe("FACE")
75-
response.data.first().orientation.shouldBe("FRONT")
76-
response.data.first().type.shouldBe("OFF_BKG")
80+
response.data[0].id.shouldBe(24299)
81+
response.data[0].active.shouldBe(true)
82+
response.data[0].captureDateTime.shouldBe(LocalDateTime.parse("2010-08-27T16:35:00"))
83+
response.data[0].view.shouldBe("FACE")
84+
response.data[0].orientation.shouldBe("FRONT")
85+
response.data[0].type.shouldBe("OFF_BKG")
86+
87+
response.data[1].id.shouldBe(24213)
88+
response.data[1].active.shouldBe(true)
89+
response.data[1].captureDateTime.shouldBe(LocalDateTime.parse("2008-08-27T16:35:00"))
90+
response.data[1].view.shouldBe("FACE")
91+
response.data[1].orientation.shouldBe("FRONT")
92+
response.data[1].type.shouldBe("OFF_BKG")
93+
}
94+
95+
it("returns sorted by newest date image metadata for the matching person ID") {
96+
val response = nomisGateway.getImageMetadataForPerson(offenderNo)
97+
98+
response.data[0].captureDateTime.shouldBe(LocalDateTime.parse("2010-08-27T16:35:00"))
99+
response.data[1].captureDateTime.shouldBe(LocalDateTime.parse("2008-08-27T16:35:00"))
77100
}
78101

79102
it("returns a person without image metadata when no images are found") {

0 commit comments

Comments
 (0)