generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PI-1484 - add endpoint to return addresses
- Loading branch information
1 parent
26a7774
commit 6ee16f4
Showing
7 changed files
with
178 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/AddressGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.AddressStatus | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Person | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.PersonAddress | ||
import java.time.LocalDate | ||
|
||
object AddressGenerator { | ||
val ADDRESS_STATUS_MAIN = generateStatus("M") | ||
val ADDRESS_STATUS_PREVIOUS = generateStatus("P") | ||
val ADDRESS_STATUS_OTHER = generateStatus("O") | ||
val ADDRESS_MAIN = generateAddress( | ||
PersonGenerator.DEFAULT_PERSON, | ||
ADDRESS_STATUS_MAIN, | ||
buildingNumber = "21", | ||
streetName = "Mantle Place", | ||
town = "Hearth", | ||
postcode = "H34 7TH" | ||
) | ||
val ADDRESS_PREVIOUS = generateAddress( | ||
PersonGenerator.DEFAULT_PERSON, | ||
ADDRESS_STATUS_PREVIOUS, | ||
buildingName = "Casa Anterior", | ||
streetName = "Plaza de Espana", | ||
county = "Seville", | ||
postcode = "S3 11E", | ||
startDate = LocalDate.now().minusDays(12), | ||
endDate = LocalDate.now().minusDays(1) | ||
) | ||
val ADDRESS_OTHER = generateAddress(PersonGenerator.DEFAULT_PERSON, ADDRESS_STATUS_OTHER) | ||
val ADDRESS_DELETED = generateAddress( | ||
PersonGenerator.DEFAULT_PERSON, | ||
ADDRESS_STATUS_OTHER, | ||
buildingNumber = "1", | ||
streetName = "Deleted Close", | ||
district = "Invisible", | ||
softDeleted = true | ||
) | ||
|
||
fun generateStatus( | ||
code: String, | ||
description: String = "Description of $code", | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = AddressStatus(code, description, id) | ||
|
||
fun generateAddress( | ||
person: Person, | ||
status: AddressStatus, | ||
buildingName: String? = null, | ||
buildingNumber: String? = null, | ||
streetName: String? = null, | ||
district: String? = null, | ||
town: String? = null, | ||
county: String? = null, | ||
postcode: String? = null, | ||
startDate: LocalDate = LocalDate.now(), | ||
endDate: LocalDate? = null, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = PersonAddress( | ||
person, | ||
status, | ||
buildingName, | ||
buildingNumber, | ||
streetName, | ||
district, | ||
town, | ||
county, | ||
postcode, | ||
startDate, | ||
endDate, | ||
softDeleted, | ||
id | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AddressService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package uk.gov.justice.digital.hmpps.service | ||
|
||
import org.springframework.stereotype.Service | ||
import uk.gov.justice.digital.hmpps.api.model.Address | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.PersonAddressRepository | ||
|
||
@Service | ||
class AddressService(private val personAddressRepository: PersonAddressRepository) { | ||
fun findAddresses(crn: String): List<Address> = | ||
personAddressRepository.findAllByPersonCrnOrderByStartDateDesc(crn).mapNotNull { | ||
Address.from( | ||
it.buildingName, | ||
it.buildingNumber, | ||
it.streetName, | ||
it.district, | ||
it.town, | ||
it.county, | ||
it.postcode, | ||
it.startDate, | ||
it.endDate | ||
) | ||
} | ||
} |