@@ -8,7 +8,9 @@ import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.D
8
8
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.DistinguishingMarkUpdateRequest
9
9
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.SourceSystem.NOMIS
10
10
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.toSourceSystem
11
+ import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.response.DistinguishingMarkPrisonDto
11
12
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.response.DistinguishingMarkDto
13
+ import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.response.DistinguishingMarkImageDetail
12
14
13
15
@Service
14
16
class DistinguishingMarksService (
@@ -17,14 +19,24 @@ class DistinguishingMarksService(
17
19
fun getDistinguishingMarks (
18
20
prisonerNumber : String ,
19
21
sourceSystem : String ,
20
- ): ResponseEntity <List <DistinguishingMarkDto >> = when (sourceSystem.toSourceSystem()) {
21
- NOMIS -> prisonApiClient.getDistinguishingMarks(prisonerNumber)
22
+ ): ResponseEntity <List <DistinguishingMarkDto >> {
23
+ when (sourceSystem.toSourceSystem()) {
24
+ NOMIS -> {
25
+ val response = prisonApiClient.getDistinguishingMarks(prisonerNumber)
26
+
27
+ return if (response.statusCode.is2xxSuccessful) {
28
+ ResponseEntity .ok(response.body?.map { toDto(it) })
29
+ } else {
30
+ ResponseEntity .status(response.statusCode).build()
31
+ }
32
+ }
33
+ }
22
34
}
23
35
24
36
fun getDistinguishingMark (markId : String , sourceSystem : String ): ResponseEntity <DistinguishingMarkDto > = when (sourceSystem.toSourceSystem()) {
25
37
NOMIS -> {
26
38
val (prisonerNumber, sequenceId) = parseMarkId(markId)
27
- prisonApiClient.getDistinguishingMark(prisonerNumber, sequenceId)
39
+ mappedResponse( prisonApiClient.getDistinguishingMark(prisonerNumber, sequenceId) )
28
40
}
29
41
}
30
42
@@ -35,7 +47,7 @@ class DistinguishingMarksService(
35
47
): ResponseEntity <DistinguishingMarkDto > = when (sourceSystem.toSourceSystem()) {
36
48
NOMIS -> {
37
49
val (prisonerNumber, sequenceId) = parseMarkId(markId)
38
- prisonApiClient.updateDistinguishingMark(request, prisonerNumber, sequenceId)
50
+ mappedResponse( prisonApiClient.updateDistinguishingMark(request, prisonerNumber, sequenceId) )
39
51
}
40
52
}
41
53
@@ -45,7 +57,7 @@ class DistinguishingMarksService(
45
57
prisonerNumber : String ,
46
58
sourceSystem : String ,
47
59
): ResponseEntity <DistinguishingMarkDto > = when (sourceSystem.toSourceSystem()) {
48
- NOMIS -> prisonApiClient.createDistinguishingMark(file, request, prisonerNumber)
60
+ NOMIS -> mappedResponse( prisonApiClient.createDistinguishingMark(file, request, prisonerNumber) )
49
61
}
50
62
51
63
fun getDistinguishingMarkImage (imageId : String , sourceSystem : String ): ResponseEntity <ByteArray > = when (sourceSystem.toSourceSystem()) {
@@ -59,7 +71,7 @@ class DistinguishingMarksService(
59
71
): ResponseEntity <DistinguishingMarkDto > = when (sourceSystem.toSourceSystem()) {
60
72
NOMIS -> {
61
73
val (prisonerNumber, sequenceId) = parseMarkId(markId)
62
- prisonApiClient.addDistinguishingMarkImage(file, prisonerNumber, sequenceId)
74
+ mappedResponse( prisonApiClient.addDistinguishingMarkImage(file, prisonerNumber, sequenceId) )
63
75
}
64
76
}
65
77
@@ -70,4 +82,24 @@ class DistinguishingMarksService(
70
82
}
71
83
return Pair (tokens[0 ], tokens[1 ].toInt())
72
84
}
85
+
86
+ private fun mappedResponse (response : ResponseEntity <DistinguishingMarkPrisonDto >): ResponseEntity <DistinguishingMarkDto > = if (response.statusCode.is2xxSuccessful) {
87
+ ResponseEntity .ok(response.body?.let { toDto(it) })
88
+ } else {
89
+ ResponseEntity .status(response.statusCode).build()
90
+ }
91
+
92
+ private fun toDto (value : DistinguishingMarkPrisonDto ): DistinguishingMarkDto = DistinguishingMarkDto (
93
+ id = value.id,
94
+ bookingId = value.bookingId,
95
+ offenderNo = value.offenderNo,
96
+ bodyPart = value.bodyPart?.toReferenceDataValue(),
97
+ markType = value.markType?.toReferenceDataValue(),
98
+ side = value.side?.toReferenceDataValue(),
99
+ partOrientation = value.partOrientation?.toReferenceDataValue(),
100
+ comment = value.comment,
101
+ createdAt = value.createdAt,
102
+ createdBy = value.createdBy,
103
+ photographUuids = value.photographUuids.map { DistinguishingMarkImageDetail (it.id, it.latest) },
104
+ )
73
105
}
0 commit comments