Skip to content

Commit

Permalink
Tidy Cas1SpaceSearchService
Browse files Browse the repository at this point in the history
Remove unneccessary private functions, inlining calls instead
  • Loading branch information
davidatkinsuk committed Jan 2, 2025
1 parent de6172e commit 5038b0b
Showing 1 changed file with 6 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
Expand All @@ -54,20 +56,6 @@ class Cas1SpaceSearchService(
)
}

private fun getCandidatePremises(
targetPostcodeDistrict: String,
requiredCharacteristics: RequiredCharacteristics,
isWomensPremises: Boolean,
): List<CandidatePremises> {
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")

Expand Down

0 comments on commit 5038b0b

Please sign in to comment.