Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-britton-moj authored Dec 19, 2023
1 parent b05418c commit 818c03f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ database:
username_key: /assessment-summary-and-delius/db-username
password_key: /assessment-summary-and-delius/db-password
tables:
- audited_interaction
- contact
- deregistration
- domain_event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ object ReferenceDataGenerator {

fun generateDataset(code: String, id: Long = IdGenerator.getAndIncrement()) = Dataset(code, id)

fun generateCourt(code: String, id: Long = IdGenerator.getAndIncrement()) = Court(code, id)
fun generateCourt(code: String, selectable: Boolean = true, id: Long = IdGenerator.getAndIncrement()) =
Court(code, selectable, id)

fun generateOffence(code: String, id: Long = IdGenerator.getAndIncrement()) = Offence(code, id)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package uk.gov.justice.digital.hmpps.integrations.delius.court.entity

import jakarta.persistence.Column
import jakarta.persistence.Convert
import jakarta.persistence.Entity
import jakarta.persistence.Id
import org.hibernate.annotations.Immutable
import org.hibernate.type.YesNoConverter
import org.springframework.data.jpa.repository.JpaRepository
import uk.gov.justice.digital.hmpps.exception.NotFoundException

Expand All @@ -12,14 +14,18 @@ import uk.gov.justice.digital.hmpps.exception.NotFoundException
class Court(
@Column(columnDefinition = "char(6)")
val code: String,

@Convert(converter = YesNoConverter::class)
val selectable: Boolean,

@Id
@Column(name = "court_id")
val id: Long
)

interface CourtRepository : JpaRepository<Court, Long> {
fun findByCode(code: String): Court?
fun findByCodeAndSelectableTrue(code: String): Court?
}

fun CourtRepository.getByCode(code: String) =
findByCode(code) ?: throw NotFoundException("Court", "code", code)
findByCodeAndSelectableTrue(code) ?: throw NotFoundException("Court", "code", code)

0 comments on commit 818c03f

Please sign in to comment.