@@ -8,15 +8,14 @@ import org.springframework.web.bind.annotation.RequestMapping
8
8
import org.springframework.web.bind.annotation.RequestParam
9
9
import org.springframework.web.bind.annotation.RestController
10
10
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.EntityNotFoundException
11
+ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.decodeUrlCharacters
11
12
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.Address
12
13
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.ImageMetadata
13
14
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.Person
14
15
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetAddressesForPersonService
15
16
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetImageMetadataForPersonService
16
17
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetPersonService
17
18
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetPersonsService
18
- import java.net.URLDecoder
19
- import java.nio.charset.StandardCharsets
20
19
21
20
@RestController
22
21
@RequestMapping(" /persons" )
@@ -43,7 +42,7 @@ class PersonController(
43
42
44
43
@GetMapping(" {encodedPncId}" )
45
44
fun getPerson (@PathVariable encodedPncId : String ): Map <String , Person ?> {
46
- val pncId = URLDecoder .decode( encodedPncId, StandardCharsets . UTF_8 )
45
+ val pncId = encodedPncId.decodeUrlCharacters( )
47
46
val result = getPersonService.execute(pncId)
48
47
49
48
if (result.isNullOrEmpty()) {
@@ -55,17 +54,17 @@ class PersonController(
55
54
56
55
@GetMapping(" {encodedPncId}/images" )
57
56
fun getPersonImages (@PathVariable encodedPncId : String ): Map <String , List <ImageMetadata >> {
58
- val pncId = URLDecoder .decode( encodedPncId, StandardCharsets . UTF_8 )
57
+ val pncId = encodedPncId.decodeUrlCharacters( )
59
58
val images = getImageMetadataForPersonService.execute(pncId)
60
59
61
60
return mapOf (" images" to images)
62
61
}
63
62
64
63
@GetMapping(" {encodedPncId}/addresses" )
65
64
fun getPersonAddresses (@PathVariable encodedPncId : String ): Map <String , List <Address >> {
66
- val pncId = URLDecoder .decode( encodedPncId, StandardCharsets . UTF_8 )
67
- val addresses =
68
- getAddressesForPersonService.execute(pncId) ? : throw EntityNotFoundException (" Could not find person with id: $pncId " )
65
+ val pncId = encodedPncId.decodeUrlCharacters( )
66
+ val addresses = getAddressesForPersonService.execute(pncId)
67
+ ? : throw EntityNotFoundException (" Could not find person with id: $pncId " )
69
68
70
69
return mapOf (" addresses" to addresses)
71
70
}
0 commit comments