1
1
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.controllers.v1
2
2
3
+ import io.swagger.v3.oas.annotations.Operation
4
+ import io.swagger.v3.oas.annotations.media.Content
5
+ import io.swagger.v3.oas.annotations.media.Schema
6
+ import io.swagger.v3.oas.annotations.responses.ApiResponse
3
7
import org.springframework.beans.factory.annotation.Autowired
4
8
import org.springframework.web.bind.annotation.GetMapping
5
9
import org.springframework.web.bind.annotation.PathVariable
@@ -9,6 +13,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.BadRequestExce
9
13
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.EntityNotFoundException
10
14
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.InternalServerErrorException
11
15
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Balances
16
+ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.DataResponse
12
17
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
13
18
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
14
19
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetBalancesForPersonService
@@ -17,7 +22,21 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetBalancesForP
17
22
@RequestMapping(" /v1/prison/{prisonId}/prisoners/{hmppsId}/balances" )
18
23
class BalancesController (@Autowired val getBalancesForPersonService : GetBalancesForPersonService ,) {
19
24
@GetMapping()
20
- fun getBalancesForPerson (@PathVariable hmppsId : String , @PathVariable prisonId : String ): Response <Balances ?> {
25
+ @Operation(
26
+ summary = " Returns a all accounts for a prisoner that they have at a prison." ,
27
+ description = " <b>Applicable filters</b>: <ul><li>prisons</li></ul>" ,
28
+ responses = [
29
+ ApiResponse (responseCode = " 200" , useReturnTypeSchema = true , description = " Successfully found a prisoner's accounts." ),
30
+ ApiResponse (
31
+ responseCode = " 400" ,
32
+ description = " The HMPPS ID provided has an invalid format or the prisoner does hot have accounts at the specified prison." ,
33
+ content = [Content (schema = Schema (ref = " #/components/schemas/BadRequest" ))],
34
+ ),
35
+ ApiResponse (responseCode = " 404" , content = [Content (schema = Schema (ref = " #/components/schemas/PersonNotFound" ))]),
36
+ ApiResponse (responseCode = " 500" , content = [Content (schema = Schema (ref = " #/components/schemas/InternalServerError" ))]),
37
+ ],
38
+ )
39
+ fun getBalancesForPerson (@PathVariable hmppsId : String , @PathVariable prisonId : String ): DataResponse <Balances ?> {
21
40
val response = getBalancesForPersonService.execute(prisonId, hmppsId)
22
41
23
42
if (response.hasError(UpstreamApiError .Type .ENTITY_NOT_FOUND )) {
@@ -31,6 +50,6 @@ class BalancesController(@Autowired val getBalancesForPersonService: GetBalances
31
50
if (response.hasError(UpstreamApiError .Type .INTERNAL_SERVER_ERROR )) {
32
51
throw InternalServerErrorException (" Error occurred while trying to get accounts for person with id: $hmppsId " )
33
52
}
34
- return response
53
+ return DataResponse ( response.data)
35
54
}
36
55
}
0 commit comments