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.
* MAN-183 - add new api * MAN-183 - add new api * MAN-183 - small refactor to create appointment and update tests * Formatting changes --------- Co-authored-by: probation-integration-bot[bot] <177347787+probation-integration-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ae0b9ca
commit 3dc7f10
Showing
21 changed files
with
419 additions
and
26 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
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
87 changes: 87 additions & 0 deletions
87
...elius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentencesIntegrationTest.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,87 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers | ||
import uk.gov.justice.digital.hmpps.api.model.sentence.* | ||
import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LC_WITHOUT_NOTES | ||
import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LC_WITH_1500_CHAR_NOTE | ||
import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LC_WITH_NOTES | ||
import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LC_WITH_NOTES_WITHOUT_ADDED_BY | ||
import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LIC_COND_MAIN_CAT | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.ACTIVE_ORDER | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.EVENT_1 | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.EVENT_2 | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.REQUIREMENT | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.REQUIREMENT_UNPAID_WORK | ||
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator | ||
import uk.gov.justice.digital.hmpps.service.toSummary | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
class SentencesIntegrationTest { | ||
@Autowired | ||
lateinit var mockMvc: MockMvc | ||
|
||
@Test | ||
fun `unauthorized status returned`() { | ||
mockMvc | ||
.perform(MockMvcRequestBuilders.get("/sentences/X123456")) | ||
.andExpect(MockMvcResultMatchers.status().isUnauthorized) | ||
} | ||
|
||
@Test | ||
fun `no active sentences`() { | ||
val response = mockMvc | ||
.perform( | ||
MockMvcRequestBuilders.get("/sentences/${PersonDetailsGenerator.PERSONAL_DETAILS.crn}").withToken() | ||
) | ||
.andExpect(MockMvcResultMatchers.status().isOk) | ||
.andReturn().response.contentAsJson<MinimalSentenceOverview>() | ||
|
||
val expected = MinimalSentenceOverview( | ||
PersonDetailsGenerator.PERSONAL_DETAILS.toSummary() | ||
) | ||
|
||
assertEquals(expected, response) | ||
} | ||
|
||
@Test | ||
fun `get active sentences`() { | ||
val response = mockMvc | ||
.perform(MockMvcRequestBuilders.get("/sentences/${PersonGenerator.OVERVIEW.crn}").withToken()) | ||
.andExpect(MockMvcResultMatchers.status().isOk) | ||
.andReturn().response.contentAsJson<MinimalSentenceOverview>() | ||
|
||
val expected = MinimalSentenceOverview( | ||
PersonGenerator.OVERVIEW.toSummary(), | ||
listOf( | ||
MinimalSentence(EVENT_2.id), | ||
MinimalSentence( | ||
EVENT_1.id, | ||
order = MinimalOrder(ACTIVE_ORDER.type.description, ACTIVE_ORDER.date), | ||
licenceConditions = listOf( | ||
MinimalLicenceCondition(LC_WITH_NOTES.id, LIC_COND_MAIN_CAT.description), | ||
MinimalLicenceCondition(LC_WITHOUT_NOTES.id, LIC_COND_MAIN_CAT.description), | ||
MinimalLicenceCondition(LC_WITH_NOTES_WITHOUT_ADDED_BY.id, LIC_COND_MAIN_CAT.description), | ||
MinimalLicenceCondition(LC_WITH_1500_CHAR_NOTE.id, LIC_COND_MAIN_CAT.description) | ||
), | ||
requirements = listOf( | ||
MinimalRequirement(REQUIREMENT.id, "1 days RAR, 1 completed"), | ||
MinimalRequirement(REQUIREMENT_UNPAID_WORK.id, "Unpaid Work - Intensive") | ||
) | ||
) | ||
) | ||
) | ||
|
||
assertEquals(expected, response) | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...us/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/UserLocationIntegrationTest.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,69 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import org.hamcrest.Matchers.equalTo | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders | ||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers.print | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath | ||
import uk.gov.justice.digital.hmpps.api.model.sentence.Address | ||
import uk.gov.justice.digital.hmpps.api.model.sentence.LocationDetails | ||
import uk.gov.justice.digital.hmpps.api.model.sentence.Name | ||
import uk.gov.justice.digital.hmpps.api.model.sentence.UserOfficeLocation | ||
import uk.gov.justice.digital.hmpps.data.generator.OffenderManagerGenerator.DEFAULT_LOCATION | ||
import uk.gov.justice.digital.hmpps.data.generator.OffenderManagerGenerator.STAFF_USER_1 | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
class UserLocationIntegrationTest { | ||
@Autowired | ||
lateinit var mockMvc: MockMvc | ||
|
||
@Test | ||
fun `unauthorized status returned`() { | ||
mockMvc | ||
.perform(MockMvcRequestBuilders.get("/user/peter-parker/locations")) | ||
.andExpect(MockMvcResultMatchers.status().isUnauthorized) | ||
} | ||
|
||
@Test | ||
fun `user not found`() { | ||
mockMvc.perform(MockMvcRequestBuilders.get("/user/user/locations").withToken()) | ||
.andDo(print()) | ||
.andExpect(MockMvcResultMatchers.status().isNotFound) | ||
.andExpect(jsonPath("$.message", equalTo("User with username of user not found"))) | ||
} | ||
|
||
@Test | ||
fun `get user locations`() { | ||
val response = mockMvc.perform(MockMvcRequestBuilders.get("/user/peter-parker/locations").withToken()) | ||
.andDo(print()) | ||
.andExpect(MockMvcResultMatchers.status().isOk) | ||
.andReturn().response.contentAsJson<UserOfficeLocation>() | ||
|
||
val expected = UserOfficeLocation( | ||
Name(STAFF_USER_1.forename, surname = STAFF_USER_1.surname), | ||
listOf( | ||
LocationDetails( | ||
DEFAULT_LOCATION.id, | ||
DEFAULT_LOCATION.description, | ||
Address( | ||
DEFAULT_LOCATION.buildingNumber, | ||
DEFAULT_LOCATION.streetName, | ||
DEFAULT_LOCATION.townCity, | ||
DEFAULT_LOCATION.county, | ||
DEFAULT_LOCATION.postcode | ||
) | ||
) | ||
) | ||
) | ||
assertEquals(expected, response) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/controller/SentencesController.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,21 @@ | ||
package uk.gov.justice.digital.hmpps.api.controller | ||
|
||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.security.access.prepost.PreAuthorize | ||
import org.springframework.web.bind.annotation.* | ||
import uk.gov.justice.digital.hmpps.service.SentenceService | ||
|
||
@RestController | ||
@Tag(name = "Sentences") | ||
@RequestMapping("/sentences/{crn}") | ||
@PreAuthorize("hasRole('PROBATION_API__MANAGE_A_SUPERVISION__CASE_DETAIL')") | ||
class SentencesController(private val sentenceService: SentenceService) { | ||
|
||
@GetMapping | ||
@Operation(summary = "Display active events") | ||
fun getOverview( | ||
@PathVariable crn: String, | ||
@RequestParam(required = false) number: String?, | ||
) = sentenceService.getActiveSentences(crn) | ||
} |
21 changes: 21 additions & 0 deletions
21
...ius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/controller/UserLocationController.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,21 @@ | ||
package uk.gov.justice.digital.hmpps.api.controller | ||
|
||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.security.access.prepost.PreAuthorize | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import uk.gov.justice.digital.hmpps.service.UserLocationService | ||
|
||
@RestController | ||
@Tag(name = "Locations") | ||
@RequestMapping("/user/{username}") | ||
@PreAuthorize("hasRole('PROBATION_API__MANAGE_A_SUPERVISION__CASE_DETAIL')") | ||
class UserLocationController(private val userLocationService: UserLocationService) { | ||
|
||
@GetMapping("/locations") | ||
@Operation(summary = "Display user locations") | ||
fun getUserOfficeLocations(@PathVariable username: String) = userLocationService.getUserOfficeLocations(username) | ||
} |
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
18 changes: 16 additions & 2 deletions
18
...on-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Sentence.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 |
---|---|---|
@@ -1,13 +1,27 @@ | ||
package uk.gov.justice.digital.hmpps.api.model.sentence | ||
|
||
import uk.gov.justice.digital.hmpps.api.model.overview.Order | ||
import java.time.LocalDate | ||
|
||
data class Sentence( | ||
val offenceDetails: OffenceDetails, | ||
val conviction: Conviction? = null, | ||
val order: Order? = null, | ||
val requirements: List<Requirement> = listOf(), | ||
val courtDocuments: List<CourtDocument> = listOf(), | ||
val unpaidWorkProgress: String?, | ||
val unpaidWorkProgress: String? = null, | ||
val licenceConditions: List<LicenceCondition> = listOf() | ||
) | ||
) | ||
|
||
data class MinimalSentence( | ||
val id: Long, | ||
val order: MinimalOrder? = null, | ||
val licenceConditions: List<MinimalLicenceCondition> = listOf(), | ||
val requirements: List<MinimalRequirement> = listOf() | ||
) | ||
|
||
data class MinimalOrder( | ||
val description: String, | ||
val startDate: LocalDate, | ||
val endDate: LocalDate? = null, | ||
) |
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
26 changes: 26 additions & 0 deletions
26
...ius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/UserOfficeLocation.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,26 @@ | ||
package uk.gov.justice.digital.hmpps.api.model.sentence | ||
|
||
data class UserOfficeLocation( | ||
val name: Name, | ||
val locations: List<LocationDetails> | ||
) | ||
|
||
data class Name( | ||
val forename: String, | ||
val middleName: String? = null, | ||
val surname: String | ||
) | ||
|
||
data class LocationDetails( | ||
val id: Long, | ||
val description: String, | ||
val address: Address | ||
) | ||
|
||
data class Address( | ||
val buildingNumber: String? = null, | ||
val streetName: String? = null, | ||
val town: String? = null, | ||
val county: String? = null, | ||
val postcode: String? = null | ||
) |
Oops, something went wrong.