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-156 - add release date to response (#4415)
* MAN-156 - add release date to response * MAN-156 - add release date to response * Formatting changes --------- Co-authored-by: probation-integration-bot[bot] <177347787+probation-integration-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
7c39355
commit 2042868
Showing
7 changed files
with
122 additions
and
6 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
34 changes: 34 additions & 0 deletions
34
...and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CustodyGenerator.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,34 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.ACTIVE_ORDER | ||
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.Custody | ||
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.Release | ||
import java.time.ZonedDateTime | ||
|
||
object CustodyGenerator { | ||
val CUSTODY_1 = Custody(IdGenerator.getAndIncrement(), ACTIVE_ORDER.id, ACTIVE_ORDER, listOf(), false) | ||
|
||
val RELEASE_1 = Release( | ||
IdGenerator.getAndIncrement(), | ||
CUSTODY_1, | ||
ZonedDateTime.now().minusDays(21), | ||
ZonedDateTime.now().minusDays(28), | ||
false | ||
) | ||
|
||
val RELEASE_2 = Release( | ||
IdGenerator.getAndIncrement(), | ||
CUSTODY_1, | ||
ZonedDateTime.now().minusDays(14), | ||
ZonedDateTime.now().minusDays(21), | ||
false | ||
) | ||
|
||
val RELEASE_3 = Release( | ||
IdGenerator.getAndIncrement(), | ||
CUSTODY_1, | ||
ZonedDateTime.now().minusDays(7), | ||
ZonedDateTime.now().minusDays(14), | ||
false | ||
) | ||
} |
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
58 changes: 58 additions & 0 deletions
58
...c/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/Custody.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,58 @@ | ||
package uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity | ||
|
||
import jakarta.persistence.* | ||
import org.hibernate.annotations.Immutable | ||
import org.hibernate.annotations.SQLRestriction | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Disposal | ||
import java.time.ZonedDateTime | ||
|
||
@Entity | ||
@Immutable | ||
@SQLRestriction("soft_deleted = 0") | ||
class Custody( | ||
@Id | ||
@Column(name = "custody_id") | ||
val id: Long, | ||
|
||
@Column(name = "disposal_id") | ||
val disposalId: Long, | ||
|
||
@OneToOne | ||
@JoinColumn(name = "disposal_id", updatable = false, insertable = false) | ||
val disposal: Disposal, | ||
|
||
@OneToMany(mappedBy = "custody") | ||
val releases: List<Release> = listOf(), | ||
|
||
@Column(columnDefinition = "number") | ||
val softDeleted: Boolean | ||
) { | ||
fun mostRecentRelease() = releases.maxWithOrNull(compareBy({ it.date }, { it.createdDateTime })) | ||
} | ||
|
||
interface CustodyRepository : JpaRepository<Custody, Long> { | ||
fun findAllByDisposalId(id: Long): List<Custody> | ||
} | ||
|
||
@Immutable | ||
@Entity | ||
@SQLRestriction("soft_deleted = 0") | ||
class Release( | ||
@Id | ||
@Column(name = "release_id") | ||
val id: Long, | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "custody_id") | ||
val custody: Custody, | ||
|
||
@Column(name = "actual_release_date") | ||
val date: ZonedDateTime, | ||
|
||
@Column(name = "created_datetime") | ||
val createdDateTime: ZonedDateTime, | ||
|
||
@Column(columnDefinition = "number") | ||
val softDeleted: Boolean | ||
) |
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