From 5038b0b31062caf71cb1bdaec50f5a1bedb75008 Mon Sep 17 00:00:00 2001 From: davidatkinsuk Date: Thu, 2 Jan 2025 11:11:24 +0000 Subject: [PATCH] Tidy Cas1SpaceSearchService Remove unneccessary private functions, inlining calls instead --- .../service/cas1/Cas1SpaceSearchService.kt | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas1/Cas1SpaceSearchService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas1/Cas1SpaceSearchService.kt index 5d86b7e8d7..72a352d8ea 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas1/Cas1SpaceSearchService.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/service/cas1/Cas1SpaceSearchService.kt @@ -28,16 +28,18 @@ class Cas1SpaceSearchService( val requiredCharacteristics = getRequiredCharacteristics(searchParameters.requirements) - return getCandidatePremises( - searchParameters.targetPostcodeDistrict, - requiredCharacteristics, + return spaceSearchRepository.findAllPremisesWithCharacteristicsByDistance( + targetPostcodeDistrict = searchParameters.targetPostcodeDistrict, + approvedPremisesType = requiredCharacteristics.apType, isWomensPremises = application.isWomensApplication!!, + premisesCharacteristics = requiredCharacteristics.groupedCharacteristics.premisesCharacteristics, + roomCharacteristics = requiredCharacteristics.groupedCharacteristics.roomCharacteristics, ) } private fun getRequiredCharacteristics(requirements: Cas1SpaceSearchRequirements) = RequiredCharacteristics( apType = if (requirements.apType != null) { - requirements.apType!!.asApprovedPremisesType() + requirements.apType.asApprovedPremisesType() } else { requirements.apTypes?.map { it.asApprovedPremisesType() }?.firstOrNull() }, @@ -54,20 +56,6 @@ class Cas1SpaceSearchService( ) } - private fun getCandidatePremises( - targetPostcodeDistrict: String, - requiredCharacteristics: RequiredCharacteristics, - isWomensPremises: Boolean, - ): List { - return spaceSearchRepository.findAllPremisesWithCharacteristicsByDistance( - targetPostcodeDistrict, - requiredCharacteristics.apType, - isWomensPremises, - requiredCharacteristics.groupedCharacteristics.premisesCharacteristics, - requiredCharacteristics.groupedCharacteristics.roomCharacteristics, - ) - } - private fun CharacteristicEntity.isPremisesCharacteristic(): Boolean = this.serviceMatches(ServiceName.approvedPremises.value) && this.modelMatches("premises")