Skip to content

Commit 83d52a1

Browse files
Refactor
1 parent 8e740de commit 83d52a1

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

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

+5-9
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,17 @@ class GetLicenceConditionService(
1313
@Autowired val getPersonService: GetPersonService,
1414
) {
1515
fun execute(hmppsId: String): Response<PersonLicences> {
16-
val personResponse = getPersonService.execute(hmppsId = hmppsId)
16+
val personResponse = getPersonService.execute(hmppsId)
1717
val crn = personResponse.data?.identifiers?.deliusCrn
1818

1919
var licences: Response<List<Licence>> = Response(data = emptyList())
2020
var personLicences = PersonLicences(hmppsId)
2121
if (crn != null) {
2222
licences = createAndVaryLicenceGateway.getLicenceSummaries(id = crn)
23-
licences.data.forEach {
24-
val licenceId = it.id.toIntOrNull()
25-
if (licenceId != null) {
26-
val conditions = createAndVaryLicenceGateway.getLicenceConditions(licenceId)
27-
it.conditions = conditions.data
28-
} else {
29-
it.conditions = emptyList()
30-
}
23+
licences.data.forEach { summary ->
24+
summary.conditions = summary.id.toIntOrNull()?.let { licenceId ->
25+
createAndVaryLicenceGateway.getLicenceConditions(licenceId).data
26+
} ?: emptyList()
3127
}
3228
personLicences = PersonLicences(hmppsId, licences.data.firstOrNull()?.offenderNumber, licences.data)
3329
}

0 commit comments

Comments
 (0)