diff --git a/projects/resettlement-passport-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt b/projects/resettlement-passport-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt index d5c4cda482..f328428735 100644 --- a/projects/resettlement-passport-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt +++ b/projects/resettlement-passport-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt @@ -4,24 +4,45 @@ import uk.gov.justice.digital.hmpps.entity.Person import uk.gov.justice.digital.hmpps.entity.PersonManager import uk.gov.justice.digital.hmpps.entity.Staff import uk.gov.justice.digital.hmpps.entity.Team +import java.time.LocalDate object PersonGenerator { - val DEFAULT = generate("X123123", "A1234YZ") + val DEFAULT = generate( + "X123123", + "A1234YZ", + "Fred", + "Williams", + LocalDate.of(1982, 8, 19), + "020 346 7982", + "07452819463", + "freddy@justice.co.uk" + ) val DEFAULT_MANAGER = generateManager(DEFAULT) - val CREATE_APPOINTMENT = generate("C123456") + val CREATE_APPOINTMENT = generate("C123456", null, "James", "Brown", LocalDate.of(1990, 5, 12)) fun generate( crn: String, noms: String? = null, + firstName: String, + surname: String, + dateOfBirth: LocalDate, + telephoneNumber: String? = null, + mobileNumber: String? = null, + emailAddress: String? = null, softDeleted: Boolean = false, id: Long = IdGenerator.getAndIncrement() - ) = - Person( - id, - crn, - noms, - softDeleted - ) + ) = Person( + id, + crn, + noms, + firstName, + surname, + dateOfBirth, + telephoneNumber, + mobileNumber, + emailAddress, + softDeleted + ) fun generateManager( person: Person, diff --git a/projects/resettlement-passport-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CaseDetailIntegrationTests.kt b/projects/resettlement-passport-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CaseDetailIntegrationTests.kt index 17b811925f..ab384cf101 100644 --- a/projects/resettlement-passport-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CaseDetailIntegrationTests.kt +++ b/projects/resettlement-passport-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CaseDetailIntegrationTests.kt @@ -10,10 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status -import uk.gov.justice.digital.hmpps.api.model.CaseIdentifiers -import uk.gov.justice.digital.hmpps.api.model.Manager -import uk.gov.justice.digital.hmpps.api.model.MappaDetail -import uk.gov.justice.digital.hmpps.api.model.Name +import uk.gov.justice.digital.hmpps.api.model.* import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator import uk.gov.justice.digital.hmpps.data.generator.ProviderGenerator import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson @@ -66,4 +63,24 @@ class CaseDetailIntegrationTests { ) assertFalse(manager.unallocated) } + + @Test + fun `person detail is returned correctly`() { + val detail = mockMvc.perform(get("/probation-cases/${PersonGenerator.DEFAULT.crn}").withToken()) + .andExpect(status().is2xxSuccessful) + .andReturn().response.contentAsJson() + + assertThat(detail.crn, equalTo(PersonGenerator.DEFAULT.crn)) + assertThat(detail.name, equalTo(Name("Fred", "Williams"))) + assertThat(detail.dateOfBirth, equalTo(LocalDate.of(1982, 8, 19))) + assertThat( + detail.contactDetails, equalTo( + ContactDetails( + "020 346 7982", + "07452819463", + "freddy@justice.co.uk" + ) + ) + ) + } } diff --git a/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/controller/CaseDetailController.kt b/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/controller/CaseDetailController.kt index 0ec4700801..ff5ef53d73 100644 --- a/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/controller/CaseDetailController.kt +++ b/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/controller/CaseDetailController.kt @@ -24,4 +24,8 @@ class CaseDetailController(private val caseDetailService: CaseDetailService) { @PreAuthorize("hasRole('PROBATION_API__RESETTLEMENT_PASSPORT__CASE_DETAIL')") @GetMapping("/{crn}/community-manager") fun getCommunityManager(@PathVariable crn: String) = caseDetailService.findCommunityManager(crn) + + @PreAuthorize("hasRole('PROBATION_API__RESETTLEMENT_PASSPORT__CASE_DETAIL')") + @GetMapping("/{crn}") + fun getPersonDetail(@PathVariable crn: String) = caseDetailService.getPersonDetail(crn) } diff --git a/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/PersonDetail.kt b/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/PersonDetail.kt new file mode 100644 index 0000000000..a752561cd3 --- /dev/null +++ b/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/PersonDetail.kt @@ -0,0 +1,21 @@ +package uk.gov.justice.digital.hmpps.api.model + +import java.time.LocalDate + +data class PersonDetail( + val crn: String, + val name: Name, + val dateOfBirth: LocalDate, + val contactDetails: ContactDetails? +) + +data class ContactDetails(val telephone: String?, val mobile: String?, val email: String?) { + companion object { + fun of(telephone: String?, mobile: String?, email: String?): ContactDetails? = + if (telephone == null && mobile == null && email == null) { + null + } else { + ContactDetails(telephone, mobile, email) + } + } +} \ No newline at end of file diff --git a/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/Person.kt b/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/Person.kt index cc8512d726..5fe892c45c 100644 --- a/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/Person.kt +++ b/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/Person.kt @@ -6,6 +6,7 @@ import jakarta.persistence.Id import jakarta.persistence.Table import org.hibernate.annotations.Immutable import org.hibernate.annotations.SQLRestriction +import java.time.LocalDate @Entity @Immutable @@ -22,5 +23,15 @@ class Person( @Column(name = "noms_number", columnDefinition = "char(7)") val noms: String?, + val firstName: String, + val surname: String, + @Column(name = "date_of_birth_date") + val dateOfBirth: LocalDate, + + val telephoneNumber: String?, + val mobileNumber: String?, + @Column(name = "e_mail_address") + val emailAddress: String?, + val softDeleted: Boolean = false ) \ No newline at end of file diff --git a/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CaseDetailService.kt b/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CaseDetailService.kt index 2492021e47..5c1e75b73f 100644 --- a/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CaseDetailService.kt +++ b/projects/resettlement-passport-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CaseDetailService.kt @@ -1,17 +1,9 @@ package uk.gov.justice.digital.hmpps.service import org.springframework.stereotype.Service -import uk.gov.justice.digital.hmpps.api.model.CaseIdentifiers -import uk.gov.justice.digital.hmpps.api.model.Manager -import uk.gov.justice.digital.hmpps.api.model.MappaDetail -import uk.gov.justice.digital.hmpps.api.model.Name -import uk.gov.justice.digital.hmpps.entity.Category -import uk.gov.justice.digital.hmpps.entity.Level -import uk.gov.justice.digital.hmpps.entity.PersonManagerRepository -import uk.gov.justice.digital.hmpps.entity.PersonRepository -import uk.gov.justice.digital.hmpps.entity.RegistrationRepository +import uk.gov.justice.digital.hmpps.api.model.* +import uk.gov.justice.digital.hmpps.entity.* import uk.gov.justice.digital.hmpps.entity.Staff -import uk.gov.justice.digital.hmpps.entity.findMappa import uk.gov.justice.digital.hmpps.exception.NotFoundException @Service @@ -37,6 +29,8 @@ class CaseDetailService( fun findCommunityManager(crn: String) = personManagerRepository.findByPersonCrn(crn)?.staff?.asManager() ?: throw NotFoundException("Person", "crn", crn) + + fun getPersonDetail(crn: String) = personRepository.getByCrn(crn).detail() } private fun String.toMappaLevel() = Level.entries.find { it.name == this }?.number @@ -50,3 +44,7 @@ private fun Staff.asManager() = if (code.endsWith("U")) { } else { Manager(Name(forename, surname), false) } + +private fun Person.detail() = PersonDetail( + crn, Name(firstName, surname), dateOfBirth, ContactDetails.of(telephoneNumber, mobileNumber, emailAddress) +)