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.
Browse files
Browse the repository at this point in the history
* PI-2035: Added activity and refactor
- Loading branch information
Showing
22 changed files
with
432 additions
and
91 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
50 changes: 50 additions & 0 deletions
50
...delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ActivityIntegrationTest.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,50 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.equalTo | ||
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.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT | ||
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.activity.PersonActivity | ||
import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.OVERVIEW | ||
import uk.gov.justice.digital.hmpps.service.toActivity | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest(webEnvironment = RANDOM_PORT) | ||
internal class ActivityIntegrationTest { | ||
@Autowired | ||
lateinit var mockMvc: MockMvc | ||
|
||
@Test | ||
fun `all person activity is returned`() { | ||
|
||
val person = OVERVIEW | ||
val res = mockMvc | ||
.perform(get("/activity/${person.crn}").withToken()) | ||
.andExpect(status().isOk) | ||
.andReturn().response.contentAsJson<PersonActivity>() | ||
|
||
assertThat(res.personSummary.crn, equalTo(person.crn)) | ||
assertThat(res.activities.size, equalTo(7)) | ||
assertThat(res.activities[2].id, equalTo(ContactGenerator.FIRST_APPT_CONTACT.toActivity().id)) | ||
assertThat(res.activities[2].type, equalTo(ContactGenerator.FIRST_APPT_CONTACT.toActivity().type)) | ||
assertThat( | ||
res.activities[2].location?.officeName, | ||
equalTo(ContactGenerator.FIRST_APPT_CONTACT.toActivity().location?.officeName) | ||
) | ||
assertThat(res.activities[2].location?.postcode, equalTo("H34 7TH")) | ||
assertThat(res.activities[2].isAppointment, equalTo(true)) | ||
assertThat(res.activities[1].documents.size, equalTo(2)) | ||
assertThat(res.activities[3].isAppointment, equalTo(false)) | ||
assertThat(res.activities[0].documents.size, equalTo(0)) | ||
assertThat(res.activities[0].action, equalTo("Breach Enforcement Action")) | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/controller/ActivityController.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.ActivityService | ||
|
||
@RestController | ||
@Tag(name = "Activity") | ||
@RequestMapping("/activity/{crn}") | ||
@PreAuthorize("hasRole('PROBATION_API__MANAGE_A_SUPERVISION__CASE_DETAIL')") | ||
class ActivityController(private val activityService: ActivityService) { | ||
|
||
@GetMapping | ||
@Operation(summary = "Gets all activity for a person’ ") | ||
fun getPersonActivity(@PathVariable crn: String) = activityService.getPersonActivity(crn) | ||
} |
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
8 changes: 8 additions & 0 deletions
8
...-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/activity/PersonActivity.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,8 @@ | ||
package uk.gov.justice.digital.hmpps.api.model.activity | ||
|
||
import uk.gov.justice.digital.hmpps.api.model.PersonSummary | ||
|
||
data class PersonActivity( | ||
val personSummary: PersonSummary, | ||
val activities: List<Activity> | ||
) |
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
3 changes: 2 additions & 1 deletion
3
...lius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/schedule/PersonAppointment.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,8 +1,9 @@ | ||
package uk.gov.justice.digital.hmpps.api.model.schedule | ||
|
||
import uk.gov.justice.digital.hmpps.api.model.PersonSummary | ||
import uk.gov.justice.digital.hmpps.api.model.activity.Activity | ||
|
||
data class PersonAppointment( | ||
val personSummary: PersonSummary, | ||
val appointment: Appointment | ||
val appointment: Activity | ||
) |
3 changes: 2 additions & 1 deletion
3
...on-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/schedule/Schedule.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,8 +1,9 @@ | ||
package uk.gov.justice.digital.hmpps.api.model.schedule | ||
|
||
import uk.gov.justice.digital.hmpps.api.model.PersonSummary | ||
import uk.gov.justice.digital.hmpps.api.model.activity.Activity | ||
|
||
data class Schedule( | ||
val personSummary: PersonSummary, | ||
val appointments: List<Appointment> | ||
val appointments: List<Activity> | ||
) |
Oops, something went wrong.