Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ewan Donovan committed Feb 26, 2025
1 parent 143435b commit 5869602
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
import org.springframework.stereotype.Repository
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.db.MatchEntity
import java.time.LocalDate
import java.time.LocalDateTime

@Repository
Expand All @@ -15,19 +14,17 @@ interface MatchRepository : JpaRepository<MatchEntity, Long> {
nomisId: String,
): MatchEntity?

fun findAllByNomisId(nomisId: String): List<MatchEntity>

@Query(
"""
SELECT m FROM MatchEntity m
WHERE m.nomisId = :nomisId
AND (:fromDate IS NULL OR m.dateCreated >= :fromDate)
AND (:toDate IS NULL OR m.dateCreated <= :toDate)
"""
""",
)
fun findForSubjectAccessRequest(
@Param("nomisId") nomisId: String,
@Param("fromDate") fromDate: LocalDateTime?,
@Param("toDate") toDate: LocalDateTime?
@Param("toDate") toDate: LocalDateTime?,
): List<MatchEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ class MatchService(
return matchRepository.save(entity).id
}

fun getDataForSubjectAccessRequest(nomisId: String, fromDate: LocalDate?, toDate: LocalDate?): List<MatchEntity> {
return matchRepository.findForSubjectAccessRequest(
nomisId,
fromDate?.atStartOfDay(),
toDate?.plusDays(1)?.atStartOfDay()?.minusNanos(1L)
)
}
fun getDataForSubjectAccessRequest(
nomisId: String,
fromDate: LocalDate?,
toDate: LocalDate?,
): List<MatchEntity> = matchRepository.findForSubjectAccessRequest(
nomisId,
fromDate?.atStartOfDay(),
toDate?.plusDays(1)?.atStartOfDay()?.minusNanos(1L),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ class SubjectAccessRequestIntegrationTest : IntegrationTestBase() {
}
}

// Try using the old code, with the param fixed
// Try using the old code, with the param fixed

0 comments on commit 5869602

Please sign in to comment.